On 07/04/2016 02:10 PM, vikash kumar wrote:
I have 2 tables:

class Table2:
    __tablename__ = 'table2'

    prov_id = sql.Column(sql.String(36)) # same as prov_id in table1
    ref_id = sql.Column(sql.String(36), sql.ForeignKey(
        'table1.id'))

class Table1:
    __tablename__ = 'table1'
    id = sql.Column(sql.String(36), primary_key=True)
    prov_id = sql.Column(sql.String(36))
    pr = sql.Column(sql.Text)
    index = sql.Column(sql.String(36))
    table2_info = orm.relationship(Table2,
                                   backref='table2_infos',
                                   cascade='all, delete-orphan')

When I am trying to delete record of Table1 all the Table2 record with
prov_id or ref_id same as record in Table1 also gets deleted. Is it
possible to restrict the deletion of Table2 record to get deleted which
match only to both prov_id and ref_id ?

you either need to have delete, delete-orphan on a relationship which features a custom primaryjoin condition that includes not just ref_id but prov_id, or alternatively forego the usage of "delete-orphan" and instead use an event such as the "after_delete" event, established on the "Table1" class, to manually emit a DELETE as needed on the current connection against the "table2" table.




--
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 [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to