2

Hi I am trying to list playlists wich contain songs by a given artist for which i have the keyname, my models are:

**playlist**
songs = db.ListProperty(db.Key)
**Song**
artist = db.ReferenceProperty(Artist,collection_name='songs')
**Artist**
Key Name = john-lennon

so playlist contains a list of song keys, and a song contains a reference to the artist.

any help would be appreciated, My queries have always been simple so far so im a little lost now :-)

Wooble
90.6k12 gold badges111 silver badges132 bronze badges
asked May 15, 2011 at 18:10

1 Answer 1

3

You can't really do queries like this with GAE. The datastore is not a relational database, and does not do things like JOINs.

The best you can do is to get all the songs whose artist is John Lennon, and then find the playlist for those songs:

songs = GqlQuery('SELECT __key__ FROM song WHERE artist = :1', 'john-lennon')
playlists = GqlQuery('SELECT * FROM playlist WHERE songs IN :1', songs)

Note that even this will have problems if you have more than 30 songs by John Lennon - as the documentation says:

Note: The IN and != operators use multiple queries behind the scenes. For example, the IN operator executes a separate underlying datastore query for every item in the list. The entities returned are a result of the cross-product of all the underlying datastore queries and are de-duplicated. A maximum of 30 datastore queries are allowed for any single GQL query.

answered May 15, 2011 at 18:54
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.