Association proxy is the way to go. And it seems like Jonathan
realized that before I had a chance to tell him :).

On 8/17/07, nerkles <[EMAIL PROTECTED]> wrote:
>
> On Aug 16, 1:33 pm, "Walter Cruz" <[EMAIL PROTECTED]> wrote:
> > Hi all!
> > I can't find nothing similitar to active record has_many_through in
> > Elixir. I need a many to many relashionship, but with a datetime
> > column in the relashiongip table. How can I do that?
>
> Currently, I do it with an AssociationProxy. I needed to relate people
> to their practice areas, sorted by whether it's their primary one,
> etc.
>
> from sqlalchemy.ext.associationproxy import AssociationProxy
> from elixir import *
>
> class Person(Entity):
>     has_field('name', Unicode)
>     has_many('pa_assoc', of_kind='PAPersonAssoc', inverse='person',
> order_by='primacy', lazy=True)
>     practice_areas = AssociationProxy('pa_assoc', 'pa')
>
> class PracticeArea(Entity):
>     has_field('name', Unicode)
>     has_many('pa_assoc', of_kind='PAPersonAssoc', inverse='pa',
> order_by='primacy', lazy=True)
>     people = AssociationProxy('pa_assoc', 'person')
>
> class PAPersonAssoc(Entity):
>     belongs_to('person', of_kind='Person', ondelete='cascade',
> lazy=False)
>     belongs_to('pa', of_kind='PracticeArea', ondelete='cascade',
> lazy=False)
>     has_field('primacy', Integer)
>
> then you can access things like:
> some_person.practice_areas[0]
> some_practice_area.people[2]
> etc.
>
> The end result is pretty much the same as Jonathan's... not sure if
> performance differs. Admittedly mine has more code and departs into
> SQLAlchemy territory a little...
>
> HTH...
>
>
-- 
Gaƫtan de Menten
http://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
-~----------~----~----~----~------~----~------~--~---

Reply via email to