I have a mixin as follows designed to remove a bunch of copy paste relationship 
code.

class UserMixin(object):
    @_declared_attr
    def user_id(cls):
        return sa.Column('user_id',typ.Integer,sa.ForeignKey("tg_user.user_id", 
ondelete="CASCADE"),nullable=False)

    @_declared_attr
    def user(cls):
        return orm.relationship("User",primaryjoin='%s.user_id == 
User.user_id'%cls.__name__)
    
    @_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__))

when I use my mixin in say a class like this:

class JournalEntry(UserMixin,DeclarativeBase):
        __tablename__ = 'journal_entries'
        #{ Columns
        id = Column(Integer,primary_key=True)
        is_private = Column(Boolean,default=False)
        modified = Column(DateTime,onupdate=datetime.datetime.now)
        text = Column(UnicodeText)
        #}

And then I:

>>> from myProject.model import *
>>> profile = DBSession.query(UserProfile).get(1)
>>> profile.journal_entries

I keep getting the error:

/Users/Me/Documents/Work/Projects/myProject/myProject/lib/python2.7/site-packages/SQLAlchemy-0.7.6-py2.7-macosx-10.7-intel.egg/sqlalchemy/orm/strategies.py:508:
 SAWarning: Multiple rows returned with uselist=False for lazily-loaded 
attribute 'UserProfile.journal_entries' 
< myProject.model.user_data.JournalEntry object at 0x10d8b26d0>

I can't figure out why it's using uselist=False, and a joined lazy load. Any 
help pointing me in the right direction would be great.

~Dave




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

Reply via email to