On 3/20/07, Mike Kent <[EMAIL PROTECTED]> wrote:

> I have a many-to-many relationship between two entities, call them A
> and B.  This is easy enough to model in sqlalchemy using Elixir.
> However, to complicate things, I need an integer column somewhere
> called 'priority'.  In the relationship between an A and multiple Bs,
> I want the Bs to be ordered by the value of the 'priority' column.  In
> the relationship between a B and multiple As, the value of 'priority'
> is irrelevant.
>
> The problem is, I don't know what entity needs to have the 'priority'
> column in it, or how to model this in the relationship between A and
> B.  I thought that maybe the 'priority' column should be in the
> secondary table that handles the many-to-many relationship between A
> and B, but I'm not sure how to set that up, and I'm not sure that
> Elixir can handle that at all.

Basically Elixir doesn't handle that case. For now, your only option
is to make a separate entity for the intermediary table, which would
hold two belongs_to relationships, and use has_many relationships in
your existing entities (A and B) to that new entity, instead of using
has_and_belongs_to_many relationships.

Now on the SQLAlchemy's side, you can either use that solution too, or
use an AssociationProxy. See:

 http://www.sqlalchemy.org/docs/plugins.html#plugins_associationproxy

I personally feel the associationproxy should be better integrated
into the normal relation function (preferably as an option), but
Michael Bayer doesn't agree with me on this. My point is that
many-to-many relationship are already doing some kind of
associationproxy behind the scenes, so I don't see why you should use
an immensely different way to set things up simply because you have
extra fields in your intermediary table.

As for Elixir, I've been thinking to integrate the associationproxy
into the has_and_belongs_to_many relationship for some time now. I'll
do it if enough people are interested.

-- 
Gaƫtan de Menten
http://openhex.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to