Mike Driscoll wrote:
> 
> On Feb 4, 8:30 am, Mike Driscoll <kyoso...@gmail.com> wrote:
> > On Feb 4, 4:24 am, "King Simon-NFHD78" <simon.k...@motorola.com>
> > 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("pr...@marvel.com")
> >
> > > I don't think this is going to update the 'pr...@dc.com' 
> row in the
> > > database to say 'pr...@marvel.com'. 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 = "pr...@marvel.com"
> >
> > > 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("pr...@marvel.com")
> 
> 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 = "prof...@image.com"
> >>> 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

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to