On Fri, 15 Sep 2006 19:13:49 +0800
lazz <[EMAIL PROTECTED]> wrote:

> 
> I follow the indentities quickstart,
> and create schema like this:
> 
> user_group = Table("user_group", metadata,
>                       Column("user_id", Integer,
>                               ForeignKey("tg_user.user_id"),
>                               primary_key=True),
>                       Column("group_id", Integer,
>                               ForeignKey("tg_group.group_id"),
>                               primary_key=True))
> 
> class Group(ActiveMapper):
>     class mapping:
>         group_id = column(Integer, primary_key=True)
>         group_name = column(Unicode(16), unique=True)
>         users = many_to_many("User", user_group, backref="groups")
> 
> class User(ActiveMapper):
>     class mapping:
>         user_id = column(Integer, primary_key=True)
>         user_name = column(Unicode(16), unique=True)
>         groups = many_to_many("Group", user_group, backref="users")
> 
> But I can't make relation between user and group, I throw exception:
> 
> AttributeError: 'User' object has no attribute 'groups'
> 
> while I "u.groups.append(g)"
> 
> How can I make the user link with group?

I don't know if there's a ticket for this or anything, but the way
ActiveMapper works and how many_to_many works, the default identity
schema for sqlalchemy only needs (will work with) one of the two
many_to_many attributes.  Pick one, delete the other.  Because of the
backref argument, the other will be created and then things will work.

Jason

-- 
Two years ago, I generated a gpg key that expired August 24, 2006
(686FD13C).  I've now generated a new one (C7EFE9F4).

Attachment: signature.asc
Description: PGP signature

Reply via email to