ActiveMapper not add a many_to_many columns as attribute of the class.

4 views
Skip to first unread message

lazz

unread,
Sep 15, 2006, 7:13:49 AM9/15/06
to turbo...@googlegroups.com
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'm lazy, I'm coding.
http://lazycoding.blogspot.com/

Jason Chu

unread,
Sep 15, 2006, 11:18:20 AM9/15/06
to turbo...@googlegroups.com

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

signature.asc

lazz

unread,
Sep 15, 2006, 12:46:22 PM9/15/06
to turbo...@googlegroups.com
Hi, Jason.
Yes, the identity work without relation of users and groups.
But I most wanna know is
why the linked column can't sepicfic as a attribute,
or how to make it as a attribute.
Is that a bug, or I just miss something?

Jason Chu

unread,
Sep 15, 2006, 1:04:16 PM9/15/06
to turbo...@googlegroups.com

Like I said. If you have one or the other of those many_to_many
specifications, it will work. If you have both or none, it won't work.

I believe it's considered a bug, but it's not a high priority.

signature.asc

lazz

unread,
Sep 18, 2006, 9:45:46 AM9/18/06
to turbo...@googlegroups.com
I use the svn, and as you say,
the reference works with only one many_to_many declaration.
Many thanks to you, Jason ;)

Reply all
Reply to author
Forward
0 new messages