This would work, although there is a lot of redundancy as you say. A couple
of other ideas I have:

   - Include the article status field in the Review itself -- this will be
   redundant too, but at least you're only duplicating one field and not the
   entire object. When you update an article's status, you'll have to do a
   query for all Review objects with that article and update the status on
   each.
   - For each Article, include a List of Review keys, so you can query on
   article.status and get a reference to all reviews for a given article from
   the Article object itself. The challenge here is maintaining the consistency
   of the many-to-many.


The first option in the list seems the most straightforward, but you'll have
to do this for each field in article that you want to query on. If you want
to do this for a lot of fields, it might be more worthwhile to explore the
second option.

- Jason

On Thu, Aug 27, 2009 at 1:08 PM, Sam Walker <am.sam.wal...@gmail.com> wrote:

> Sorry, let me write it down with keys just to make sure we are on the same
> page:
>
> Article {
>   HashSet<Key> reviews; // Keys of reviews
>   HashSet<String> tags;
>   int status; // derived from all Reviews' statuses.
> }
>
> Review {
>   Key article;
>   Key reviewer;
>   int status;
> }
>
> Reviewer {
>   String email;
> }
>
> Now, do you suggest that I make Article embedded in Review? One article may
> have many reviews, that would mean the same article is embedded in all of
> them? Will that work fine? I just saw a lot of redundancy here, but if thats
> the best way, thats the best way!
>
> Thanks!
>
>
> On Thu, Aug 27, 2009 at 1:03 PM, Sam Walker <am.sam.wal...@gmail.com>wrote:
>
>> Yes, it is a key. I just wanted to make it obvious which Keys are
>> involved. I read the Embedded class as well, its not what I want here I
>> think.
>>
>> How would you model this scenario then? Both models I discussed in my
>> original post have issues.
>>
>>
>> On Thu, Aug 27, 2009 at 11:22 AM, Jason (Google) <apija...@google.com>wrote:
>>
>>> JDO supports syntax like article.status but App Engine's datastore
>>> doesn't support joins so you'll have to make article an embedded object in
>>> order to use the query as you have it below:
>>>
>>> http://code.google.com/appengine/docs/java/datastore/dataclasses.html#Embedded_Classes
>>>
>>> Also, how have you defined reviewerParam? Is it a Key object or are you
>>> actually passing in the Reviewer object? The latter won't work, but I'll
>>> follow up about the former (querying on a Key).
>>>
>>> - Jason
>>>
>>>
>>> On Sun, Aug 23, 2009 at 11:18 PM, Sam Walker <am.sam.wal...@gmail.com>wrote:
>>>
>>>> Also, I get this error: *Can only filter by properties of a sub-object
>>>> if the sub-object is embedded.* when I tried to access article while
>>>> setting a fitler: query.setFilter("reviewer == reviewerParam  &&
>>>> article.status = articleStatusParam");
>>>>
>>>> What am I missing?
>>>>
>>>>
>>>> On Sat, Aug 22, 2009 at 6:02 PM, Sam Walker <am.sam.wal...@gmail.com>wrote:
>>>>
>>>>> In the second model, how will I find all Articles being reviewed by A
>>>>> and B?
>>>>>
>>>>> The only way I can think of is adding another derived field in Article:
>>>>>
>>>>> Article {
>>>>>   HashSet<Review> reviews;
>>>>>   HashSet<Reviewer> reviewers; // keys of Reviewers to help the query
>>>>> "find all articles reviewed by A and B"
>>>>>   HashSet<String> tags;
>>>>>   int status; // derived from all Reviews' statuses.
>>>>> }
>>>>>
>>>>> Review {
>>>>>   Article article;
>>>>>   Reviewer reviewer;
>>>>>   int status;
>>>>> }
>>>>>
>>>>> Now I should be able to do "reviewers.contains(A.key) and
>>>>> reviewers.contains(B.key)". Is that the best way?
>>>>>
>>>>>
>>>>> On Sat, Aug 22, 2009 at 2:02 PM, Sam Walker 
>>>>> <am.sam.wal...@gmail.com>wrote:
>>>>>
>>>>>> Oh sweet, I didn't know that.
>>>>>>
>>>>>> That's awesome! Thanks for the quick reply.
>>>>>>
>>>>>>
>>>>>> On Sat, Aug 22, 2009 at 1:51 PM, datanucleus <
>>>>>> andy_jeffer...@yahoo.com> wrote:
>>>>>>
>>>>>>>
>>>>>>> > I dont think I can do sth like (I can't access article.tags,
>>>>>>> article.status
>>>>>>> > as far as I know, correct?):
>>>>>>>
>>>>>>> Of course you can. JDO spec defines JDOQL, using Java syntax.
>>>>>>>
>>>>>>> > query.setFilter("reviewer == reviewerParam && status == statusParam
>>>>>>> &&
>>>>>>> > article.tags == tagParam && article.status = articleStatusParam");
>>>>>>>
>>>>>>> What is "tagParam" ? an element of the hashSet?
>>>>>>> You can't do "Collection == element" in Java so you can't in JDOQL.
>>>>>>> You could do "article.tags.contains(tagParam)"
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>
> >
>

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

Reply via email to