Question

I am building an application with a many to many relationship; An item of entity 'Picture' can be linked to any number of Galleries ('Gallery'). And of course a Gallery can hold any number of Pictures.

So, following the Google Suggestion here, I will use a List at 'Picture' which holds the foreign keys of 'Gallery'. This is the BigTable approach.

(The old-style Relational DB approach would be to have a table / entity in between 'Picture' and 'Gallery'.)

Here's my question: When storing the Key, should I go for a "StringListProperty" on 'Picture' or would a "ListProperty(db.Key)" work better?

One reason I see for a StringList would be, that I could store also other values then Keys, but on the other hand that would be dirty style anyway. But I am also pretty sure that Google suggested not to use more then one List at an entity because the Index(es) will explode. So this will keep me a backdoor.

As for the ListProperty with type "Key" one point would be the automatic verification, if the value is actually a Key.

As it is very easy to convert Strings to Keys and vice versa, I don't see any reason for one of the List types to prefer here.

When it comes to performance issues, I have no idea on how I could test this - but it looks like this will be the main factor in this decision.

Curious about your input. Especially if someone has tested the performance on this or would be so kind and do it.

Cheers, //Hannes

Was it helpful?

Solution

Use a db.ListProperty(db.Key) if you're intending to store lists of keys. They will be stored in a binary representation, which is more compact than the string representation you would use in a string list.

You're right that mixing keys with other objects in a list is messy. Having multiple lists in an entity is fine, as long as you don't index more than one of them in the same custom index - that is what causes exploding indexes.

OTHER TIPS

Use db.ListProperty(db.Key), this is will make the data fetch easier than string.. if Gallery model has property had pic_list which is of type db.ListProperty(db.Key), which contains the list of keys of picture entity.. Suppose Picture is the name of your entity.. then Picture.get(//GalleryObject//.pic_list) will get all the picture entites..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top