[google-appengine] Re: How to query through multiple models?

2009-01-01 Thread Alexander Kojevnikov

> What query would return all parents with children named 'Joe'?

De-normalise! Add a StringListProperty to the Parent, and update it
with all children of that parent. You can then query the parents
directly.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: How to query through multiple models?

2009-01-01 Thread Tom

I was afraid that would be the answer.

On Jan 1, 8:14 pm, Alexander Kojevnikov 
wrote:
> > What query would return all parents with children named 'Joe'?
>
> De-normalise! Add a StringListProperty to the Parent, and update it
> with all children of that parent. You can then query the parents
> directly.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: How to query through multiple models?

2009-01-01 Thread Tiago S.

I´m facing the exactly same problem. I thought about querying all(with
a fetch(100), in my case) the children with name 'Joe', and then put
all the parent keys in a list(with a list comprehension, maybe). With
all the keys, query the Parent using Parent.get(list).

Is this acceptable or the de-normalization is the way to go in this
case?

Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: How to query through multiple models?

2009-01-01 Thread Alexander Kojevnikov

It will certainly work though it's not as efficient as querying de-
normalised parents. You can try this approach first and if it's not
fast enough for your app, you can always de-normalise later.

On Jan 2, 2:59 pm, "Tiago S."  wrote:
> I´m facing the exactly same problem. I thought about querying all(with
> a fetch(100), in my case) the children with name 'Joe', and then put
> all the parent keys in a list(with a list comprehension, maybe). With
> all the keys, query the Parent using Parent.get(list).
>
> Is this acceptable or the de-normalization is the way to go in this
> case?
>
> Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: How to query through multiple models?

2009-01-01 Thread Tiago S.

Thanks, Alexander! I´ll try that first as I´m still reluctant in doing
de-normalization.

Regards,

On Jan 2, 2:05 am, Alexander Kojevnikov 
wrote:
> It will certainly work though it's not as efficient as querying de-
> normalised parents. You can try this approach first and if it's not
> fast enough for your app, you can always de-normalise later.
>
> On Jan 2, 2:59 pm, "Tiago S."  wrote:
>
> > I´m facing the exactly same problem. I thought about querying all(with
> > a fetch(100), in my case) the children with name 'Joe', and then put
> > all the parent keys in a list(with a list comprehension, maybe). With
> > all the keys, query the Parent using Parent.get(list).
>
> > Is this acceptable or the de-normalization is the way to go in this
> > case?
>
> > Thanks
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: How to query through multiple models?

2009-01-02 Thread Rodrigo Moraes

On Fri, Jan 2, 2009 at 1:59 AM, Tiago S. wrote:
> I´m facing the exactly same problem. I thought about querying all(with
> a fetch(100), in my case) the children with name 'Joe', and then put
> all the parent keys in a list(with a list comprehension, maybe). With
> all the keys, query the Parent using Parent.get(list).

You can simply do [entity.parent for entity in result]. If you have a
ReferenceProperty, the first time you call the property "parent" to
get the key, it'll be fetched. So building and fetching a list would
only be possible if you store an additional property with the parent
key - or you'd be doing double fetch.

-- rodrigo

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: How to query through multiple models?

2009-01-02 Thread djidjadji

parents = db.get([Entity.parent.get_value_for_datastore(entity) for
entity in result])

Is more efficient because you only do 1 call to the datastore, for
multiple objects.

2009/1/2 Rodrigo Moraes :
>
> On Fri, Jan 2, 2009 at 1:59 AM, Tiago S. wrote:
>> I´m facing the exactly same problem. I thought about querying all(with
>> a fetch(100), in my case) the children with name 'Joe', and then put
>> all the parent keys in a list(with a list comprehension, maybe). With
>> all the keys, query the Parent using Parent.get(list).
>
> You can simply do [entity.parent for entity in result]. If you have a
> ReferenceProperty, the first time you call the property "parent" to
> get the key, it'll be fetched. So building and fetching a list would
> only be possible if you store an additional property with the parent
> key - or you'd be doing double fetch.
>
> -- rodrigo
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---



[google-appengine] Re: How to query through multiple models?

2009-01-02 Thread Rodrigo Moraes

On Fri, Jan 2, 2009 at 9:25 AM, djidjadji wrote:
> parents = db.get([Entity.parent.get_value_for_datastore(entity) for
> entity in result])
>
> Is more efficient because you only do 1 call to the datastore, for
> multiple objects.

Awesome... I thought it was not possible to get the key from a
ReferenceProperty without fetching the related entity.

This is a nice trick. :-)

-- rodrigo

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---