On Mon, Mar 18, 2019 at 10:30 AM Денис Ралко <ralk...@gmail.com> wrote:
>
> Hi, I have some issue
>
> I try implement track logic
> I have 2 Models and connecting Table
>
> My first class
>
> class MODEL_1(object):
>     # some values
>
>     # relations:
>     attr_1 = db.relationship('MODEL_2',
>                            secondary="test2test",
>                            lazy='dynamic',
>                            primaryjoin="MODEL_1.id == test2test.c.first_id",
>                            secondaryjoin='test2test.c.second_id == 
> Site.entity_id')
>
> Second class
>
> class MODEL_2(object):
>     # some values
>     attr_2 = db.relationship('MODEL_1', secondary='test2test', lazy='dynamic')
>
>
> And relation table
>
>
> t_ = db.Table(
>     'test2test',
>     db.Model.metadata,
>
>     db.Column('first_id', db.Integer,
>               db.ForeignKey('MODEL_1.entity_id'),
>               nullable=False),
>     db.Column('second_id', db.Integer,
>               db.ForeignKey('MODEL_2.id'),
>               nullable=False),
>     db.UniqueConstraint('first_id', 'second_id', name='uq_test2test')
> )
>
>
> I have some questions
>
> 1. can i do some table event what will fire, when will change some values in 
> t_ table ?

via the relationship, sure, use @validates or AttributeEvents for
MODEL_1.attr1, MODEL_2.attr2

https://docs.sqlalchemy.org/en/latest/orm/events.html?highlight=attributeevents#sqlalchemy.orm.events.AttributeEvents


>
> 2. if i set before_flush event and change some in MODEL_1, event fire, but 
> session have no modified objects

you would need to send along a complete example illustrating what you're doing.



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

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