On Apr 24, 2012, at 7:22 PM, David Bowser wrote: > > On Apr 24, 2012, at 7:18 PM, David Bowser <[email protected]> wrote: > >> >> On Apr 24, 2012, at 6:14 PM, Michael Bayer <[email protected]> wrote: >> >>> >>> On Apr 24, 2012, at 5:59 PM, David Bowser wrote: >>> >>>> >>>> On Apr 24, 2012, at 5:50 PM, Michael Bayer <[email protected]> >>>> wrote: >>>> >>>>> one-to-many is defined as parent->child where child has a foreign key >>>>> column referring to parent; many-to-one is the reverse, where parent has >>>>> a foreign key that refers to child. When you tell the ORM "foreign_keys >>>>> = [some_col_on_parent]", that tells SQLA that the parent refers to the >>>>> child, hence many-to-one, hence uselist is set to False. >>>> >>>> >>>> My apologies for not being precise. >>>> >>>> I stated in the original message that the warning is occurring when using >>>> the backref. So it defines many entries -> one profile fine, but when I >>>> used the backref it still had uselist set to False. >>> >>> UserMixin.user_id -> JournalEntry.id , foreign key is established as >>> JournalEntry.id via the "foreign_keys" argument which propagates by default >>> to the backref, so UserMixin.user_profile evaluates as one-to-many, hence >>> uselist=True, JournalEntry.journal_entries evaluates as many-to-one, hence >>> uselist=False. >>> >>> If you enable INFO logging for the "sqlalchemy.orm" logger, it will output >>> the "direction" that it picks up on for all relationships. >> >> Look at that again: >> >> @_declared_attr >> def user_profile(cls): >> return orm.relationship('UserProfile',primaryjoin="%s.user_id == >> UserProfile.id"%cls.__name__, >> foreign_keys=lambda:[metadata.tables['user_profiles'].c.id], >> backref=cls.__tablename__ if cls.__tablename__ else >> tablename(cls.__name__)) >> >> UserMixin.user_id -> UserProfile.id >> >> The foreign_key is set as UserProfile.id, which should make >> JournalEntry.user_profile evaluate as one-to-many as per your statement >> above. UserProfile.journal_entries should be many-to-one. >> >> That is exactly what happens.... >> >> Relevant Log Lines with that code: >> >> 19:07:35,441 INFO [sqlalchemy.orm.mapper.Mapper] >> (JournalEntry|journal_entries) initialize prop user_profile >> 19:07:35,441 INFO [sqlalchemy.orm.properties.RelationshipProperty] >> JournalEntry.user_profile setup primary join journal_entries.user_id = >> user_profiles.id >> 19:07:35,442 INFO [sqlalchemy.orm.mapper.Mapper] >> (UserProfile|user_profiles) _configure_property(journal_entries, >> RelationshipProperty) >> 19:07:35,442 INFO [sqlalchemy.orm.properties.RelationshipProperty] >> JournalEntry.user_profile local/remote pairs [(journal_entries.user_id / >> user_profiles.id)] >> 19:07:35,442 INFO [sqlalchemy.orm.properties.RelationshipProperty] >> JournalEntry.user_profile relationship direction <symbol 'ONETOMANY> >> 19:07:35,442 INFO [sqlalchemy.orm.properties.RelationshipProperty] >> JournalEntry.user_profile secondary synchronize pairs [] >> 19:07:35,442 INFO [sqlalchemy.orm.properties.RelationshipProperty] >> JournalEntry.user_profile setup secondary join None >> 19:07:35,442 INFO [sqlalchemy.orm.properties.RelationshipProperty] >> JournalEntry.user_profile synchronize pairs [(journal_entries.user_id => >> user_profiles.id)] >> 19:07:35,442 INFO [sqlalchemy.orm.properties.RelationshipProperty] >> UserProfile.journal_entries setup primary join journal_entries.user_id = >> user_profiles.id >> 19:07:35,442 INFO [sqlalchemy.orm.properties.RelationshipProperty] >> UserProfile.journal_entries setup secondary join None >> 19:07:35,443 INFO [sqlalchemy.orm.properties.RelationshipProperty] >> UserProfile.journal_entries local/remote pairs [(user_profiles.id / >> journal_entries.user_id)] >> 19:07:35,443 INFO [sqlalchemy.orm.properties.RelationshipProperty] >> UserProfile.journal_entries relationship direction <symbol 'MANYTOONE> >> 19:07:35,443 INFO [sqlalchemy.orm.properties.RelationshipProperty] >> UserProfile.journal_entries secondary synchronize pairs [] >> 19:07:35,443 INFO [sqlalchemy.orm.properties.RelationshipProperty] >> UserProfile.journal_entries synchronize pairs [(journal_entries.user_id => >> user_profiles.id)]
sorry, I'm getting names mixed up because your example is not complete and it slipped my mind that JournalEntry extends UserMixin. Above, UserProfile.journal_entries, primaryjoin is user_profiles_id->journal_entries.user_id, foreign key is user_profiles.id, which is local to UserProfile - many to one. -- 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.
