That is perfectly valid too.The tradeoff is that when ever a url entity is
returned the list is serialized.
If you know you want the tag list most of the time then place it with the
url.
However if you are only interested in using the list for lookups, then you
can place it as an IndexModel in the Url entity group.

Even more food for thought....
If your url is not very long...
Then you can use it as the key_name for the Url/Tag entity.
Then you can do a __keys_only__ query

A)
    class URL(db.Model):
      url = db.StringProperty()
      tags = db.StringListProperty()
      # psuedo code
      key_name = url


B)
    class URL(db.Model):
      url = db.StringProperty()
      # psuedo code ...
      key_name = url


    class Tags(db.Model):
      tags = db.StringListProperty()
      # psuedo code ...
      key_name = url


a query against A for __keys_only__ will return faster than returning the
entity.  and your fetch density will be higher.
urlkey.name() will give you the url without making datastore retrieve the
entity.

B wouldn't require Tags to be in the URL entity group, unless you really
want transaction capabilities on that.
They can simply have the same key_name. thus creating a 1 to 1 relationship
between URL and Tags.

if URL has a bunch more properties this would make more sense. however if
the 2 fields you have mentioned are the only ones and your URLs are not
super long.. I would use the key_name trick.   This also means you can do
db.get(key) for retrieving or testing url existence.  This is faster then a
query for 2 reasons.

1. Query for an entity is 2 datastore calls under the hood (1st to setup the
query, 2nd to fetch results) and requires 2 operations inside datastore (1st
index scan for keys, 2nd locate and retrieve entities)

2. db.get for an entity is 1 datastore call and no index lookups.

So if you want your datastore access to fly think about leveraging the
key_name as a useful pkey.


Cheers,
Kevin


On Fri, Oct 9, 2009 at 8:51 AM, Stephen <sdea...@gmail.com> wrote:

>
>
>
> On Oct 8, 9:00 pm, Shailen <shailen.t...@gmail.com> wrote:
> >
> > Option 2, use list properties:
> >
> >    class URL(db.Model):
> >        url = db.StringProperty()
> >
> >    class Tags(db.Model):
> >        tags = db.StringListProperty()
> >
> > Store a list of tags with a URL key as parent.
>
>
> Why not simply add the tags to the URL entity?
>
> class URL(db.Model):
>    url = db.StringProprety()
>    tags = db.StringListProperty()
>
>    @classmethod
>    def fetch_by_tag(cls, *tags):
>        query = URL.all()
>        for t in tags:
>            query.filter('tags =', t)
>        return query.fetch()
>
> urls = URL.fetch_by_tag('foo', 'bar', 'baz')
>
>
> >
>


-- 
Kevin Pierce
Software Architect
VendAsta Technologies Inc.
kpie...@vendasta.com
(306)955.5512 ext 103
www.vendasta.com

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to