Hi,

I'd like to setup bidirectionnal data synchornization between the
lastname attribute of two related models

class User(Base):  
  __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    lastname = Column(String(50))
    userdatas = relationship('UserDatas',
primaryjoin='User.id==UserDatas.user_id', back_populates='user',
uselist=False)

class UserDatas(Base):
    __tablename__ = 'userdatas'
    id = Column(Integer, primary_key=True)
    lastname = Column(String(50))
    user_id = Column(ForeignKey('users.id'))
    user = relationship('User', primaryjoin='User.id==UserDatas.user_id')


I thought I could do something like this :

def sync_lastname_user_to_userdatas(target, value, oldvalue, initiator):
    target.userdatas.lastname = value

listen(User.lastname, 'set', sync_lastname_user_to_userdatas)

def sync_lastname_userdatas_to_user(target, value, oldvalue, initiator):
    target.user.lastname = value

listen(UserDatas.lastname, 'set', sync_lastname_userdatas_to_user)


The obvious problem here is the infinite loop that is generated

So :
Is there a way to set an attribute without firing the 'set' event ?

I tend to think there is a better way to do that, does anybody have an
advice to share ?

Thanks in advance

Regards,
Gaston Tjebbes

https://www.majerti.fr

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