On 8/25/15 10:05 AM, Jakub Bąk wrote:
I just came across a solution to this problem. Adding 'with_polymorphic': '*' to __mapper_args__ on the Node model was enough.

|
classNode(db.Model):
   id =db.Column(db.Integer,primary_key=True)
   type =db.Column(db.String(20))
   name =db.Column(db.String(30),nullable=False)
   date_added =db.Column(db.DateTime,default=datetime.now())
parent_id =db.Column(db.Integer,db.ForeignKey('node.id <http://node.id/>'),nullable=True)
   path =db.Column(db.String(200),default='')
   __mapper_args__ ={'polymorphic_on':type,
'with_polymorphic':'*'}
|


OK, yeah that's a funny problem you have. The with_polymorphic in all cases is going to lead to heavier queries, because there's the join but also if you already have joins between Node classes, you'll start to see some very long queries with lots of joins / sub-joins.

A more portable solution would be to also implement before_delete(), where you either ensure that the Image columns are loaded, or you add the files to be deleted to some kind of collection; then you'd actually delete the files using a safer event like after_commit(), so that way if your transaction fails, the files are preserved.





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

Reply via email to