I'm not certain of the answer to that - the easiest thing is probably
just to try it.

Remember that session.merge() doesn't modify the instance that you
pass in - it returns a different instance associated with the target
session, so code normally looks more like this:

    u_source = User(id=1)
    u_target = session.merge(u_source)
    session.commit()

My *guess*, based on the paragraph that you quoted, is that the name,
gender and address properties *don't exist* on the source instance,
and so won't be transferred as NULLs to the target instance, but
without testing it I couldn't be sure.

Simon

On Fri, Jul 18, 2014 at 12:46 AM, Bao Niu <[email protected]> wrote:
> For example, if I have User class which is mapped to user table. In user
> table there is a single row, whose id (primary key) equals 1, like this:
>>
>> id |  name | gender | address
>> 1     John       male     second best bathroom street, toilet#2
>
> now I have this code:
>>
>> u = User(id=1)
>> session.merge(u)
>> session.commit()
>
> because the incoming data contains only id attribute and nothing more,
> should I expect after execution the above code will wipe out that row and
> get something like this:
>>
>> id |  name | gender | address
>> 1     Null       Null      Null
>
>
> My reason for such expectation is because of this in documentation:
>>
>>  For mapped attributes which aren’t present on the source, the attribute
>> is expired on the target instance, discarding its existing value.
>
>
> By the way, does this have something to do with "If load is passed as False,
> the incoming data is *stamped* directly "?
>
> Thanks.
>
> On Tuesday, July 15, 2014 5:57:59 PM UTC-7, Bao Niu wrote:
>>
>> In the documentation for session.merge() method, there is a section on the
>> mechanism of reconciling if the load=true is set:
>>>
>>> If the load=True flag is left at its default, this copy process emits
>>> events and will load the target object’s unloaded collections for each
>>> attribute present on the source object, so that the incoming state can be
>>> reconciled against what’s present in the database. If load is passed as
>>> False, the incoming data is “stamped” directly without producing any
>>> history.
>>
>>
>> I don't quite understand the relationship between "stamped" and without
>> "stamped". The author is apparently trying to contrast something important
>> here, but I just couldn't imagine what a stamp could be here. Could someone
>> explain this process in a newbie-friendlier way please? Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to