> -----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 object><book2 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 object><book2 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 -~----------~----~----~----~------~----~------~--~---