This is a duplicate mail (due to a recent SMTP problems). Don't reply. DS
ml píše v Po 11. 12. 2006 v 23:13 +0100: > Hi! > > I have a little questions about how does the SA work: > > Example: > ======== > I borrowed a model from SA documentation example User/Address. My mapper > is > > mapper(Address, addresses_table) > mapper(User, users_table, properties = { > 'addresses' : relation(Address, cascade="all, delete-orphan") > } > ) > > My example code: > ---------------- > u = User("a", "b") > u.addresses.append(Address("1","2","3","4")) > u.addresses.append(Address("1","2","3","4")) > session.save(u) > session.flush() > session.clear() > print "**********" > u = session.query(User).get_by_user_name("a") > session.delete(u) > session.flush() > > Output: > ----------- > BEGIN > INSERT INTO users (user_name, password) VALUES (?, ?) > ['a', 'b'] > INSERT INTO addresses (user_id, street, city, state, zip) VALUES > (?, ?, ?, ?, ?) > [1, '1', '2', '3', '4'] > INSERT INTO addresses (user_id, street, city, state, zip) VALUES > (?, ?, ?, ?, ?) > [1, '1', '2', '3', '4'] > COMMIT > ********** > SELECT users.user_name AS users_user_name, users.password AS > users_password, users.user_id AS users_user_id > FROM users > WHERE users.user_name = ? ORDER BY users.oid > LIMIT 1 OFFSET 0 > ['a'] > BEGIN > SELECT addresses.city AS addresses_city, addresses.address_id AS > addresses_address_id, addresses.user_id AS addresses_user_id, > addresses.zip AS addresses_zip, addresses.state AS addresses_state, > addresses.street AS addresses_street > FROM addresses > WHERE ? = addresses.user_id ORDER BY addresses.oid > [1] > DELETE FROM addresses WHERE addresses.address_id = ? > [[1], [2]] > DELETE FROM users WHERE users.user_id = ? > [1] > COMMIT > > Question about deleting: > ------------------------ > 1) Why does the SA the second SELECT for addresses to obtain primary > keys? Why there is not a direct "DELETE FROM addresses WHERE user_id=?"? > 2) If it is neccessary to do this SELECT, why is the SA selecting all > columns? E.g. I will have 1 user with 100000 addresses - an idea of > selecting all 100000 addresses to get their id's is spooky :-) > > Why is it so or em I missing something? > > Thank you. > > David > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---