So, what's happening here is that when a class gets registered there
is a mapping from kind to class just as Nick said.  This mapping will
be the last class that you created with that unqualified name.  In
this case, your last mapping is y.A.  From that point on, every time
you load an entity from datastore of kind A, it will create an
instance of y.A even if it was originally created as x.A.

  App Engine deliberately doe not try to prevent developers from
defining more than one class with the same name more than once.
Developers need to be careful about keeping that space unambiguous.

  You can use the kind method to store fully qualified instance names
which will allow you to use classes with the same name in different
modules.

On Oct 21, 11:43 pm, Tonny <mezz...@gmail.com> wrote:
> Thank you or the reply. This is great news - if I understood it
> correctly it means moving model classes to new modules is possible
> (redesign/cleanups).
>
> What i don't understand is how GAE searches for the actual class,
> given that it only has an unqualified name. Does it iterate all
> modules in the app or something else?
>
> Cheers
> Tonny
>
> On 21 Okt., 16:37, "Nick Johnson (Google)" <nick.john...@google.com>
> wrote:
>
>
>
> > Hi Tonny,
> > The SDK maintains a mapping between kind name and class. The kind name is
> > determined by calling kind() on your class, and defaults to the
> > (unqualified) name of the class. Because you have two classes with the same
> > name in different modules, they both have the same kind name.
>
> > The solution is to override kind() on one or both classes:
>
> > class MyModel(db.Model):
> >   @classmethod
> >   def kind(self):
> >     return 'some_other_value'
>
> > -Nick Johnson
>
> > On Wed, Oct 21, 2009 at 11:00 AM, Tonny <mezz...@gmail.com> wrote:
>
> > > I ran into a fuzzy little thing today. I have to classes with the same
> > > name in different modules and both inherits from the Model class
> > > (let's call them x.A and y.A). I've created an instance of x.A (let's
> > > call it a1) and put it to the datastore, i then referenced the
> > > instance from an a.B entity (let's say b1). Now later fetching b1 and
> > > accessing the a1 through the reference property on b1 i get an object
> > > of the class y.A. How did this happen?
>
> > > Maybe i should put this to code:
>
> > > module x
> > > class A(db.Model):
> > >  name = db.StringProperty()
> > > class B(db.Model):
> > >  name = db.StringProperty
> > >  other = db.ReferenceProperty(reference_class=A)
>
> > > module y
> > > class A(db.Model):
> > >  name = db.StringProperty()
>
> > > # now let's create som entities
> > > a1 = x.A(name='Test')
> > > a1.put()
> > > b1 = x.B(name = 'Some Name', other=a1)
> > > b1.put()
> > > b2 = x.B.all().filter('name =', 'Some Name').get()
> > > a2 = b2.other # now this will be an instance of y.A, even though we've
> > > created no such instance or worked with module y in module a or the
> > > end code snippet.
>
> > > Magic, a bug, a feature?
>
> > > Regards
> > > Tonny
>
> > --
> > Nick Johnson, Developer Programs Engineer, App Engine
> > Google Ireland Ltd. :: Registered in Dublin, Ireland, Registration Number:
> > 368047
--~--~---------~--~----~------------~-------~--~----~
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