Hello everyone:
Let's say I have a class "User" and a class "UserGroup". One user can
belong to one userGroup, an a userGroup can contain several users
(pretty typical structure). It's a simple relationship I got modeled
like:
class UserGroup(declarativeBase):
"""Represents a group of users with the same features"""
__tablename__ = "user_groups"
id = Column("id", Integer, primary_key=True)
name = Column("name", String(50))
users = relationship("User", order_by=lambda:User.userName,
cascade="all, delete", collection_class=set)
class User(declarativeBase):
"""Represents a user"""
__tablename__ = "users"
id = Column("id", Integer, primary_key=True)
firstName = Column("first_name", String(50))
lastName = Column("last_name", String(50))
email = Column("email", String(60))
userName = Column("user_name", String(50), unique=True, nullable=False)
password = Column("password", String(64), nullable=False)
userGroupId = Column("user_group_id", Integer,
ForeignKey("user_groups.id"))
userGroup = relationship("UserGroup", uselist=False)
I am working in a tool that accepts generic queries, and, basically, I
can do something like:
session.query(User.User).filter(User.User.id > 3).values("userName")
And get tuples with a .userName field with all the userNames of the
users whose id is > 3
But if I try:
session.query(User.User).filter(User.User.id > 3).values("userGroup")
I get an error:
OperationalError: (OperationalError) (1054, "Unknown column
'userGroup' in 'field list'") 'SELECT userGroup' ()
session.query(User.User).filter(User.User.id > 3).values("userGroup")
I have also tried:
session.query(User.User.userGroup).filter(User.User.id >= 3).all()
but, doing this, I get all the user information, not the userGroup
So here's the question:
Is there any way of getting the "userGroup" value somehow "starting"
(or querying) User objects? (or what would be the best way, if there
are many ways)
Thank you!
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en.