Walter Cruz wrote:

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

We don't have the exact equivalent for this right now, but its
definitely something I want to add.  You can get really close to this
already.  Here is an example:


     from elixir import *
     from datetime import datetime

     class Person(Entity):
         has_field('name', Unicode)
         has_many(
             'assignments',
             of_kind='Assignment',
             inverse='person'
         )

         @property
         def projects(self):
             return (a.project for a in self.assignments)

     class Project(Entity):
         has_field('title', Unicode)
         has_many(
             'assignments',
             of_kind='Assignment',
             inverse='project'
         )

     class Assignment(Entity):
         has_field('start_date', DateTime)
         belongs_to(
             'person',
             of_kind='Person',
             inverse='assignments'
         )
         belongs_to(
             'project',
             of_kind='Project',
             inverse='assignments'
         )

     if __name__ == '__main__':
         metadata.connect('sqlite:///')
         metadata.create_all()

         jon = Person(name='Jonathan')
         daniel = Person(name='Daniel')
         elix = Project(title='Elixir')
         a1 = Assignment(
             person=jon,
             project=elix,
             start_date=datetime.now()
         )
         a2 = Assignment(
             person=daniel,
             project=elix,
             start_date=datetime.now()
         )

         objectstore.flush(); objectstore.clear()

         p1 = Person.get(1)
         for project in p1.projects:
             print project.title


You could make the "projects" property on Person writable as well, if
you did a little extra work.  I am planning on working on `has_many`
with a `through` keyword argument at some point in the future to
automatically create the properties, but haven't gotten around to it
yet (and might not anytime soon, depending on my schedule).

--
Jonathan LaCour
http://cleverdevil.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