[sqlalchemy] Group delete with inheritance

2014-07-15 Thread Pavel Aborilov
Hi! I have two models class DB_Object(Base): __tablename__ = 'objects' id = Column(Integer, primary_key=True) name = Column(String(50), unique=True, nullable=False) type = Column(String(50), default="object") __mapper_args__ = { 'polymorphic_identity': 'object', 'polymorphi

[sqlalchemy] Mechanism of reconciling for merge method

2014-07-15 Thread Bao Niu
In the documentation for *session.merge()* method, there is a section on the mechanism of reconciling if the *load=true* is set: > If the load=True flag is left at its default, this copy process emits > events and will load the target object’s unloaded collections for each > attribute present o

Re: [sqlalchemy] List Objects To Be Deleted

2014-07-15 Thread Scott Meisburger
fabulous, this works great. thanks! now I've got something like this in my code: def delete_cascade_preview(instance): keys = [rel.key for rel in inspect(instance.__class__).relationships if rel.cascade.delete == True] return {key:getattr(instance, key).all() for key in keys if getattr(

Re: [sqlalchemy] List Objects To Be Deleted

2014-07-15 Thread Michael Bayer
I'd look at inspect(MyClass).relationships to see where the linkages are to other classes. Then you can probe those for the features you need - once you have one, it has a string "key". you can then see that by just getattr(someobj, "somekey"). On Jul 15, 2014, at 3:40 PM, Scott Meisburger

[sqlalchemy] List Objects To Be Deleted

2014-07-15 Thread Scott Meisburger
I've got an app where through an admin interface, a user can delete objects in the database. This happens via: db.session.delete(obj) db.session.commit() There are cascade rules defined in Python for these objects (using the ORM). What I want to do is display to the user a list of related objec

Re: [sqlalchemy] Update instead of delete on collection

2014-07-15 Thread Michael Bayer
On Jul 15, 2014, at 1:56 PM, Mariano Mara wrote: > > But actually I don't want to lose track of the relation between parent and > child. Of course, the easiest solution would be to perform the update in the > ORM step but I have to use a common class to handle all ORM actions and I > have to

Re: [sqlalchemy] Update instead of delete on collection

2014-07-15 Thread Mariano Mara
2014-07-15 14:47 GMT-03:00 Michael Bayer : > > On Jul 15, 2014, at 1:27 PM, Mariano Mara wrote: > > > Hi all > > > > Each time my Parent class is edited and one of the elements from its > Child relationship is removed I want to "invalidate" this element (e.g. > element.valid=False) instead of act

Re: [sqlalchemy] Update instead of delete on collection

2014-07-15 Thread Michael Bayer
On Jul 15, 2014, at 1:27 PM, Mariano Mara wrote: > Hi all > > Each time my Parent class is edited and one of the elements from its Child > relationship is removed I want to "invalidate" this element (e.g. > element.valid=False) instead of actually performing the delete DML > instruction. How

[sqlalchemy] Update instead of delete on collection

2014-07-15 Thread Mariano Mara
Hi all Each time my Parent class is edited and one of the elements from its Child relationship is removed I want to "invalidate" this element (e.g. element.valid=False) instead of actually performing the delete DML instruction. How can I achieve that? I have created a "remove" event listener and

[sqlalchemy] How to represent relationship between user, category and item in each category or how to get the Parent-Child-Subchild correctly with flask-sqlalchemy.

2014-07-15 Thread suvir
I'm using Flask-SQLAlchemy and flask on server side. I want to create a relationship between User(Parent), Category(Child) and item(Subchild). I don't know if a parent-child-subchild is right way to approach this but my end goal is to easily fetch all the items rated by user in each category. F

Re: [sqlalchemy] How to use multiple foreign keys as composite primary key in sqlalchemy?

2014-07-15 Thread Simon King
On Tue, Jul 15, 2014 at 3:09 PM, Calvin Chen wrote: > Hi, > > I try to create a 'UserFavoriteTopic' table in sqlachemy that uses 'user_id' > and 'topic_id' as primary key(unique togher). > > How should I implement this? Any suggestions would be appreciated. > > My current implementation: > ===

[sqlalchemy] How to use multiple foreign keys as composite primary key in sqlalchemy?

2014-07-15 Thread Calvin Chen
Hi, I try to create a 'UserFavoriteTopic' table in sqlachemy that uses 'user_id' and 'topic_id' as primary key(unique togher). How should I implement this? Any suggestions would be appreciated. My current implementation: === class TopicFavorite(d