[sqlalchemy] Re: Info needed regarding the use of cascade
I got you now Thank you Simon --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Info needed regarding the use of cascade
Thank you Michael , you only need a single relation() + backref(), books-stock. did you mean like this ? class Stock(declarative_base): __tablename__ = 'tbl_stock' pass class Book(declarative_base): __tablename__ = 'tbl_books' stock = relation('Stock', backref=backref ('tbl_books',order_by=id)) if so how can i retrieve all the books in a particular stock ?? in my case i could have done it by ins_stock = session.querry(Stock).filter(id=100).one() print ins.stock.books [book1 objectbook2 object ...] --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Info needed regarding the use of cascade
-Original Message- From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of ---[EMAIL PROTECTED]@il06exr02.mot.com Sent: 18 November 2008 10:04 To: sqlalchemy Subject: [sqlalchemy] Re: Info needed regarding the use of cascade Thank you Michael , you only need a single relation() + backref(), books-stock. did you mean like this ? class Stock(declarative_base): __tablename__ = 'tbl_stock' pass class Book(declarative_base): __tablename__ = 'tbl_books' stock = relation('Stock', backref=backref ('tbl_books',order_by=id)) if so how can i retrieve all the books in a particular stock ?? in my case i could have done it by ins_stock = session.querry(Stock).filter(id=100).one() print ins.stock.books [book1 objectbook2 object ...] The 'backref' of a relation is the name of a property that gets placed on the 'other end' of the relation, pointing back at the original object. So with the configuration that you had above, you should be able to say: ins_stock = session.query(Stock).filter(id=100).one() print ins_stock.tbl_books [book1 objectbook2 object ...] If you name your backref 'books', then you can use your Stock objects in exactly the same way as you did before. Hope that helps, Simon --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Info needed regarding the use of cascade
On Nov 15, 2008, at 6:03 AM, --- [EMAIL PROTECTED] --- wrote: i have tried giving cascade = 'a'',delete-orphan' but errors comes you should use delete-orphan for that functionality. If there are error messages, feel free to ask what they mean. Also you have redundant relations set up, which shouldn't break anything but there's no need for them - books-tbl_stock and stock-tbl_books . tbl_books represents the same thing as books, and tbl_stock represents the same thing as stock. You only need a single relation() + backref(), books-stock. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---