私はSQLAlchemyに単純なClient
モデルを持っており、主に宣言型を使用しています。このモデルにはname
フィールドがあり、モデルと多対多の関係がありMetaphoneCode
ます。コードは次のようになります。
class MetaphoneCode(Base):
"""Represents a metaphone code
"""
__tablename__ = 'mcodes'
id = Column(Integer, Sequence('mcodes_seq_id'), primary_key=True)
code = Column(String(20), index=True, nullable=False)
client_mcode_assoc_table = Table(
'client_mcodes',
Base.metadata,
Column('client_id', ForeignKey('clients.id')),
Column('mcode_id', ForeignKey('mcodes.id')))
class Client(Base):
__tablename__ = 'clients'
id = Column(Integer, Sequence('client_id_seq'), primary_key=True)
name = Column(Unicode(100), index=True)
mcodes = relationship('MetaphoneCode', secondary=client_mcode_assoc_table)
ここで、metaphone コードname
自体が変更されたときに変更する必要があるため、この必要性を表現してclient.name = "John Doe"
、それらの名前 (姓と名) に関連する metaphone コードを計算し、mcodes
関係を更新したいと考えています。
更新:以下に引用する簡単な解決策を見つけました。私の質問は、「ORM 属性イベント システムは、別の属性の変更に応じて属性を更新するためのベスト プラクティス メカニズムですか?」