MappedForeignKey : Access to .obj field after update
<dl>
<dt>Module</dt>
<dd>Mapper</dd>
<dt>Request</dt>
<dd>When updating the referenced object in a MappedForeignKey column, the .is field returns the new value of the id, but the .obj field still returns the reference of the object originally loaded with the owner.
The .is and .obj should be coherent.</dd>
<dt>Example</dt>
<dd>
<dt>See</dt>
<dd> http://groups.google.com/group/liftweb/browse_thread/thread/0041894ec33fc538/0bcb1a85658155af?hl=en#0bcb1a85658155af </dd>
</dl>
Regarding to this thread
<dt>Module</dt>
<dd>Mapper</dd>
<dt>Request</dt>
<dd>When updating the referenced object in a MappedForeignKey column, the .is field returns the new value of the id, but the .obj field still returns the reference of the object originally loaded with the owner.
The .is and .obj should be coherent.</dd>
<dt>Example</dt>
<dd>
val testUser : User = User.find(By(User.id, 1)).open_! val testAddress = testUser.homeAddress.obj; Log.debug("Current FK id is "+testUser.homeAddress.is) // returns 1 testAddress match { case Full(addr) => val anotherAddr : Address = Address.find(By(Address.id,2)).open_! Log.debug("There was an address: "+addr+". Replace it with addr id#2: "+anotherAddr); testUser.homeAddress(anotherAddr).save case _ => [...] } val retestAddress = testUser.homeAddress.obj Log.debug("Now obj is "+retestAddress); // returns a Box with the old address (id == 1) Log.debug("And is is "+testUser.homeAddress.is) // returns 2</dd>
<dt>See</dt>
<dd> http://groups.google.com/group/liftweb/browse_thread/thread/0041894ec33fc538/0bcb1a85658155af?hl=en#0bcb1a85658155af </dd>
</dl>
Regarding to this thread
Leave a comment
on 2010-02-06 12:49 *
By github.importer
Imported from GitHub: http://github.com/dpp/liftweb/issues/165/find