I use dynamic constructor for class.
It works fine for instance who have not foreign keys. But when FK on 
another instance it cannot load them

Example:
class left (Base):
  id = sqlalchemy.Column(UUID, primary_key = True)
  def __getattr__(self, attribute):
    if attribute == 'rights':
      right().left
      return getattr(self, attribute)

class right(Base):
  id = sqlalchemy.Column(UUID, primary_key = True)
  def __getattr__(self, attribute):
    if attribute == 'left':
      rel_key = sqlalchemy.Column(UUID, sqlalchemy.ForeignKey(left.mRID), 
nullable = True)
      setattr(self.__class__, 'left_mRID', rel_key)
      setattr(self.__class__, 'left', sqlalchemy.orm.relationship(left,\
               foreign_keys = rel_key, uselist = False,\
               backref = sqlalchemy.orm.backref('rights', uselist = True)))
      return getattr(self,attribute)      

Works:
left_1 = session.query(left).first()
print (str(left_1.rights))

Not works:
right_1 = session.query(right).first()
print (str(right_1.left))
I think that it may be fix them, but i need universal for all 
relationshipproperties
class right(Base):
  ...
  def __getattr__(self, attribute):
...
    session.refresh(self, attribute_names = ['left_mRID'])

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to