Re: [sqlalchemy] Defining a relationship without a foreign key constraint?

2011-03-15 Thread Mike Conley
The foreign key and join condition can be specified as part of the relation
definition without having the foreign key existing in the database

class User(Base):
__tablename__ = 'users'
logon = Column(String(10), primary_key=True)
group_id = Column(Integer)

class Group(Base):
__tablename__ = 'groups'
group_id = Column(Integer, primary_key=True)
group_nm = Column(String(10))
users = relation('User', backref='grp',
primaryjoin='User.group_id==Group.group_id',
foreign_keys='User.group_id')


-- 
Mike Conley

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Defining a relationship without a foreign key constraint?

2011-03-15 Thread recurse
I'm wondering if there is a way to define a relationship without
creating an associated foreign key constraint in the database.  It
seems like relationship() requires me to define a foreign key, and
that in turn automatically creates a foreign key constraint.  I'm
currently using the declarative syntax to define my tables.

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.