On Apr 30, 11:32 am, Yap Sok Ann <[EMAIL PROTECTED]> wrote:
> The model below doesn't seem to work with any of the import methods
> laid out in this discussion and in the wiki. It has an "odd many-to-
> many relationship" which is modeled following Gaeten's suggestion 
> inhttp://www.mail-archive.com/[EMAIL PROTECTED]/msg02616.html
>
> man.py
> ------
> from elixir import Entity, Field, Unicode, has_many
>
> class Man(Entity):
>     name = Field(Unicode(10))
>     has_many('relationships', of_kind='Relationship')
>     def __repr__(self):
>         return '<Man \'%s\'>' % (self.name)
>
> woman.py
> --------
> from elixir import Entity, Field, Unicode, has_many
>
> class Woman(Entity):
>     name = Field(Unicode(10))
>     has_many('relationships', of_kind='Relationship')
>     def __repr__(self):
>         return '<Woman \'%s\'>' % (self.name)
>
> relationship.py
> ---------------
> from elixir import Entity, Field, Unicode, belongs_to
>
> class Relationship(Entity):
>     name = Field(Unicode(10))
>     belongs_to('man', of_kind='Man', required=True)
>     belongs_to('woman', of_kind='Woman', required=True)
>     def __repr__(self):
>         return '<Relationship \'%s\'>' % (self.name)
>
> Tested under Elixir 0.5.2

I got it to work using full path addressing as mentioned by Gaeten in
http://groups.google.com/group​/sqlelixir/browse_thread/thread​/bc8b23a1ae8bd9ec

Dan, can you try if it works for you? Should work fine regardless of
how to structure the files or where to do the import.

FWIW, here's what I have:

model/__init__.py
-----------------


model/man.py
------------
from elixir import Entity, Field, Unicode, has_many

c​lass Man(Entity):
    name = Field(Unicode(10))
    has_many('re​lationships', of_kind='model.relationship.Re​
lationship')
    has_many('women', through='relationships', via='woman')
    def __repr__(self):
        return '<Man \'%s\'>' % (self.name)

model/woman.py
------​--------
from elixir import Entity, Field, Unicode, has_many

class Woman(Entity):
    name = Field(Unicode(10))
    has_many('relationships',
of_kind='model.relationship.Relationship')
    has_many('men', through='relationships', via='man')
    def __repr__(self):
        return '<Woman \'%s\'>' % (self.name)

model/relationship.py
---------------------
from elixir import Entity, Field, Unicode, belongs_to

class Relationship(Entity):
    name = Field(Unicode(10))
    belongs_to('man', of_kind='model.man.Man',
inverse='relationships', required=True)
    belongs_to('woman', of_kind='model.woman.Woman',
inverse='relationships', required=True)
    def __repr__(self):
        return '<Relationship \'%s\'>' % (self.name)

test.py
-------
from elixir import Entity, setup_all

from model.man import Man
from model.woman import Woman
from model.relationship import Relationship

print Entity.__metaclass__._entities

setup_all()

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

Reply via email to