On Feb 4, 9:26 am, "King Simon-NFHD78" <[email protected]> wrote: > Mike Driscoll wrote: > > > On Feb 4, 8:30 am, Mike Driscoll <[email protected]> wrote: > > > On Feb 4, 4:24 am, "King Simon-NFHD78" <[email protected]> > > > wrote: > > [SNIP] > > > > > > > > > Not a serious blunder, but I think there may be a small > > mistake in part > > > > 2, where you describe updating an email address: > > > > > # change the first address > > > > prof.addresses[0] = Address("[email protected]") > > > > > I don't think this is going to update the '[email protected]' > > row in the > > > > database to say '[email protected]'. Instead, it is going > > to disconnect > > > > that row from the user by setting the user_id to NULL, > > and add a new row > > > > with the new address. (This may be what you intended, but > > I don't think > > > > it's clear from the description). > > > > > I would have thought that you'd actually want to write this: > > > > > # change the first address > > > > prof.addresses[0].email_address = "[email protected]" > > > > > Hope that helps, > > > > > Simon > > > > I was testing this in IDLE and it seemed to work when I did > > > prof.addresses to check it. If the user gets set to NULL, wouldn't > > > prof.addresses only show one entry? I'll check it out and make sure. > > > If I messed it up, I'll get it fixed. Thanks for the bug report! > > > > - Mike > > > I just ran through that section again using the Python interpreter and > > after changing the address like this: > > > prof.addresses[0] = Address("[email protected]") > > > I then used the following (per the official tutorial): > > > >>> prof.addresses[0].user > > <User('Prof','Prof. Xavier', 'fudge')> > > > So my method appears to work. I tried your method too: > > > >>> prof.addresses[0].email_address = "[email protected]" > > >>> prof.addresses[0].user > > <User('Prof','Prof. Xavier', 'fudge')> > > > That appears to give the same result. Let me know if I am > > misunderstanding something basic here. > > The difference is that in your case, there is now a row in the Address table > without an associated User. Try running the following: > > for address in session.query(Address): > print "Address %r belongs to User %r" % (address, address.user) > > I think you will see addresses that don't belong to any users. > > Simon
Thanks Simon! That made sense. I've fixed my example to match what you said. Sorry about that. - Mike -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. 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.
