relationship attributes

1 view
Skip to first unread message

anderbubble

unread,
May 29, 2007, 1:36:30 PM5/29/07
to SQLElixir
Say I have user/group classes:

class User (Entity):
has_field("name", String)
has_and_belongs_to_many("groups", of_kind="Group", \
inverse="users", tablename="membership")

class Group (Entity):
has_field("name", String)
has_and_belongs_to_many("users", of_kind="User", \
inverse="groups", tablename="membership")

What if I wanted relational attributes? That is, attributes on the
relationship itself? Say I wanted to track when a user joined a group.
I would then define:

class Membership (Entity):
has_field("join_date", DateTime)

But here I get an error:

sqlalchemy.exceptions.ArgumentError: Table 'membership' is already
defined for this MetaData instance.

Now, there's probably somewhere where I can tell Elixir to not
automatically create the intermediate table "membership" with the
specification of the relationship between User and Group, but this
asks the larger question of how SQLElixir is meant to accommodate
relational attributes.

When I was using SQLObject, I would make Membership a primary entity,
and have User and Group have 1:M relationships with Membership, but it
would be better if the concept of attributes on a M:M relationship was
just supported in the syntax.

Thanks.

Reply all
Reply to author
Forward
0 new messages