shaylevi2
shaylevi2

Reputation: 672

Same Kind Entities Groups

Let's take an example on which I run a blog that automatically updates its posts.

I would like to keep an entity of class(=model) BlogPost in two different "groups", one called "FutureBlogPosts" and one called "PastBlogPosts".

This is a reasonable division that will allow me to work with my blog posts efficiently (query them separately etc.).

Basically the problem is the "kind" of my model will always be "BlogPost". So how can I separate it into two different groups?

Here are the options I found so far:

  • Duplicating the same model class code twice (once FutureBlogPost class and once PastBlogPost class (so their kinds will be different)) -- seems quite ridiculous.

  • Putting them under different anchestors (FutureBlogPost, "SomeConstantValue", BlogPost, #id) but this method also has its implications (1 write per second?) and also the whole ancestor-child relationship doesn't seem fit here. (and why do I have to use "SomeConstantValue" if I choose that option?)

  • Using different namespaces -- seems too radical for such a simple separation

What is the right way to do it?

Upvotes: 0

Views: 74

Answers (2)

shaylevi2
shaylevi2

Reputation: 672

Well seems like I finally found the relevant article.

As I understand it, pulling all entities by a specific kind and pulling them by a specific property would make no difference, both will require the same type of work on the background. (However, querying by a specific full-key, is still faster)

So basically adding a property named "Type" or any other property you want to use to split your specific entities into groups is just as useful as giving it a certain kind.

Read more here: https://developers.google.com/appengine/articles/storage_breakdown

As you see, both EntitiesByKind and EntitiesByProperty are nothing but index tables to the original key.

Finally, an answer.

Upvotes: 1

Patrice
Patrice

Reputation: 4692

Why not just put a boolean in your "BlogPost" Entity, 0 if it's past, 1 if it's future? will let you query them separately easily.

Upvotes: 0

Related Questions