Lift-mongodb-record and BsonRecordField in 2.5-M2

55 views
Skip to first unread message

Arseny Tolmachev

unread,
Oct 28, 2012, 2:31:05 AM10/28/12
to lif...@googlegroups.com
I switched to 2.5-M2 and found out that update operation on a record that has BsonRecordField doesn't propagate changes of inner bson record.
It worked on 2.4, so is it a regression or a change in design?

Here's a small test case https://gist.github.com/3967864

Tim Nelson

unread,
Oct 29, 2012, 7:00:32 AM10/29/12
to lif...@googlegroups.com
Hi,

I'll take a look at it this week. Thanks for reporting and including example code.

Tim

Tim Nelson

unread,
Nov 3, 2012, 3:35:13 PM11/3/12
to lif...@googlegroups.com
Hello,

This problem is related to the fact that Field.setBox now checks equality before setting the dirty flag. There are actually 2 problems with BsonRecordField. The first one is there isn't a proper equals method for BsonRecord. I've fixed this by adding one to Record.

The second problem stems from the fact that Record (and BsonRecord) Fields are mutable. So, when you do:
    
    val str = smt2.struct.is
    str.fld0("cat")

You're actually modifying the original value, so when setBox goes to compare them they are the same. To help alleviate this I did 2 things:

* Added a copy method to Record that creates a new Record instance with all fields set to the values in the original instance
* Added forceDirty_? to Field. Setting this to true will force the dirty flag to always be set when calling setBox, the same as the previous behavior.

So, you'll be able to either override forceDirty_? and set it to true, or change the above code to:

    val str = smt2.struct.is.copy
  str.fld0("cat")

I've issued a pull request for these changes: https://github.com/lift/framework/pull/1351

Tim
Reply all
Reply to author
Forward
0 new messages