worked like a charm!
thanks gaëtan
On Oct 11, 4:03 am, "Gaetan de Menten" <[EMAIL PROTECTED]> wrote:
> On 10/11/07, Dean Landolt <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > I've been beating my head against the wall trying to figure out how to
> > append any class to a class. Below is a simple model...
>
> > class Resource(Entity):
> > has_field('name', Unicode)
> > has_and_belongs_to_many('children', of_kind='Resource',
> > enable_typechecks=False)
> > has_and_belongs_to_many('parents', of_kind='Resource',
> > enable_typechecks=False)
> > has_one('metaclass', of_kind='MetaClass', enable_typechecks=False)
>
> > def __repr__(self):
> > return '<Resource name="%s">' % self.name
>
> > class MetaClass(Entity):
> > belongs_to('resource', of_kind='Resource')
>
> > class File(Entity):
> > has_field('filename', Unicode)
> > has_field('hash', String(32))
> > belongs_to('resource', of_kind='Resource', inverse='asset')
>
> > def __repr__(self):
> > return '<File filename="%s">' % (self.filename)
>
> > When I create a resource and append File object to it, it seems to
> > work just fine, but the flush apparently fails silently -- both
> > objects get created, but their association goes away...
>
> > r = Resource(name='testresource')
> > r.metaclass = File(filename='yadayada')
> > r.flush()
>
> Well, it doesn't work that way. To get polymorphism, you should make
> File inherit from MetaClass and use:
> using_options(polymorphic=True)
> in both classes.
>
> Note that this will only work with Elixir trunk and not 0.3.
>
> Hope this helps,
> --
> Gaëtan de Mentenhttp://openhex.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---