On 4/6/07, Mike Kent <[EMAIL PROTECTED]> wrote:

> I'd like to revisit this topic, because I'm wondering if I can mix
> both Elixir DSL statements and SQLAlchemy statements in order to get
> the kind of many-to-many relationship I'm after.
>
> If I do the following:
>
> class A(Entity):
>     has_field('name', String(30))
>
> class B(Entity):
>     has_field('name', String(30))
>
> I will have deliberately left out the association table for the many-
> to-many relationship I want between an A and a B.  Can I then (in the
> same model.py file) do something like:
>
> a_to_b_table = Table('a_to_b', metadata,
>     Column('A_id', Integer, ForeignKey("A.A_id")),
>     Column('B_id', Integer, ForeignKey("B.B_id"))
>
> )
>
> mapper(A, A_table, properties = dict(
>     keywords = relation(B, secondary=a_to_b_table, lazy=False)
>     )
> )

You cannot redefine the mapper for class A, as it is already defined
by Elixir. What you can generally do though is (as Isaac showed) to
add a property to the mapper Elixir created for you. The best way to
do so is to use the add_property method on the mapper, so the above
code would translate to:

A.mapper.add_property('keywords', relation(B, secondary=a_to_b_table,
lazy=False))

Now, the problem is that SQLAlchemy explicitly warn against doing
many2many relationships  with an intermediary table mapped to an
object (see my next message to Isaac).

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