When do CBLModel values get updated from the CBLDocument after a sync?

24 views
Skip to first unread message

Brendan Duddridge

unread,
Sep 14, 2016, 7:17:46 PM9/14/16
to Couchbase Mobile
Hi,

I'm debugging a sync issue and I'm seeing a situation where the CBLDocument has been correctly updated after a sync on my iPhone from a change I made on my Mac, but the associated property on the CBLModel subclass has not updated from the sync.

Here's what a fragment of my CBLDocument looks like on my iPhone after my iPhone pulls the changes from the Mac:

(lldb) po [self.formEntry.document properties]

{

    values =     {

        "fld-0323bba4bfa54faa924da9128e298264" = "There we are again stuff";

        "fld-0c1953513df54c07ae9b30ba3c44f93e" = 1;

        "fld-1ebe3f684e764f01a9278bd458852c65" = 1;

        "fld-1ecbf04de9734e6198b5a0512a3d8e86" = DJ;


And here's what my CBLModel looks like for the same values property on the iPhone:

(lldb) po [self.formEntry values]

{

    "fld-0323bba4bfa54faa924da9128e298264" = "There we are";

    "fld-0c1953513df54c07ae9b30ba3c44f93e" = 1;

    "fld-1ebe3f684e764f01a9278bd458852c65" = 1;

    "fld-1ecbf04de9734e6198b5a0512a3d8e86" = DJ;


I've defined my "values" property as such:

@property (nullable, nonatomic, strong) NSDictionary *values;


And in my implementation I have values defined as @dynamic:


@dynamic values;


Notice the content in red is different. I would have expected that the values property in the CBLModel would contain the same data as the values property in the CBLDocument's properties dictionary.

This could be a source of the problem I posted earlier about losing data from a peer-to-peer sync. Because what's happening is that when I close the database and re-open it, the value that I changed to "There we are again stuff"  is being replaced by the value "There we are" even though I made the change by adding "again stuff" to the string on the first device.
 
Do I need to force the CBLModel instances to update themselves after a sync? Or do I need to refetch them from the database in order to get updated data in my model objects?

Thanks,

Brendan

Jens Alfke

unread,
Sep 14, 2016, 10:33:44 PM9/14/16
to mobile-c...@googlegroups.com

On Sep 14, 2016, at 4:17 PM, Brendan Duddridge <bren...@gmail.com> wrote:

Do I need to force the CBLModel instances to update themselves after a sync? Or do I need to refetch them from the database in order to get updated data in my model objects?

No, the model object should automatically update whenever the document does. This is weird.

The update of the CBLModel’s properties is triggered by a call from -[CBLDocument revisionAdded:notify:]. I can’t think of how the CBLDocument’s properties could change without this happening.

—Jens

Brendan Duddridge

unread,
Sep 14, 2016, 11:15:41 PM9/14/16
to Couchbase Mobile
Maybe because what's actually changing is a value within an NSDictionary property and not the entire values property itself?

Brendan Duddridge

unread,
Sep 15, 2016, 3:56:24 AM9/15/16
to Couchbase Mobile
After doing more tests, it does seem that the problem is due to the dictionary of values not being updated from the CBLModel's document:didChange: method.

 If I change a property that's directly on my model class, such as an "isFavourite" flag, it gets updated in the CBLDocument AND the CBLModel subclass after a sync.  Just not when I change a value inside my NSDictionary of values.

I suspect that could also happen with any collection class, such as an array property?

Brendan Duddridge

unread,
Sep 15, 2016, 11:59:18 AM9/15/16
to Couchbase Mobile
I've filed this as an issue in GitHub because I think it's a bug of some sort:


Reply all
Reply to author
Forward
0 new messages