Hello Joel and Jens,
We had the same issue to have models with a parent/children relationship. 

We started with the same solution but we realized it was not possible to do 
as in a relational database because of synchronisation issues.
Effectively, what would happen if a parent is synchronized with a pull or 
push while it is not the case of one of its children because the 
communication stops precisely at the wrong time ? 
In fact, we may have a pb of consistency.

So, instead, we decided to use the nested objects (as soon they were!) 
implemented by Jens. In such case, parent and children are saved inside the 
same document and thus, there is no issue in terms of consistency.
Furthermore, cascading delete is straightforward: if you remove the parent, 
it removes the children too !

Nested objets involve some work, but we think -and we hope !- it worth 
it (we choose to generate the code from the Xcode entity model tool, so it 
is no more a difficulty for us).

Laurent


Le dimanche 23 février 2014 00:17:29 UTC+1, Joel Saltzman a écrit :
>
> Awesome. I did it right. Thanks for the weekend support!
>
> On Saturday, February 22, 2014 3:15:58 PM UTC-8, Jens Alfke wrote:
>>
>>
>> On Feb 22, 2014, at 2:39 PM, Joel Saltzman <[email protected]> wrote:
>>
>> Let's say I have a model (subclass of CBLModel) with many children. 
>> Is this the suggested way of setting up the relationship? 
>>
>>
>> Yes; assuming that you’ve defined a MyModel.children property, marked it 
>> as @dynamic in the implementation, and implemented a +childrenItemClass 
>> method that returns MyModel.
>>
>> Is there a better way to do it so when the parent gets deleted, the 
>> children get deleted too?
>>
>>
>> No, there’s no support for cascading deletes. CBLModel doesn’t do 
>> everything CoreData does, although it does keep getting closer.
>> If you want this behavior you’d need to override -deleteDocument: and 
>> delete each of the child objects. (You might need some kind of protection 
>> against infinite regress, if your relationship can have cycles.)
>>
>> —Jens
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/be76cf92-f59a-4638-907d-caa18610554f%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to