Hi OC,

The ValueFactory methods are not well suited for you need. You want to create a 
child relationship serialized in the parent object, not a simple storage for 
basic container.

I suggest you try something like this with the model attribute for the 
serialized content named attributeBlob with a NSData type:

- Implement a method public NSData _attributeBlob() that will returns the 
serialized attribute.

- Implement a method public void _setAttributeBlob(NSData data) that will 
unserialize your blob to an instance variable with the back link to it's parent.

- Add a getter for the real attribute object like public MyCustomObject 
attribute()

- In the attribute object add a call to willChange() on the parent EO in method 
that mutate the object.

EOF will uses the method with an '_' during fetch and save if they exists 
(StoredValueForKey: protocol) so you can uses theses for your encoding 
decoding. The call to willChange() will add the object in the EOEditingContext 
changed objects.

I've done something similar without the backlink part in the past.

Regards,

Samuel


> Le 22 août 2018 à 13:31, ocs@ocs <o...@ocs.cz> a écrit :
> 
> Hi there,
> 
> quite unrelated to the other things, I would need to exploit the 
> ValueFactory/ValueConversion support of EOF to store my own complex values in 
> BLOBs.
> 
> There's a catch though: for a ValueFactory-generated object, I would need to 
> know which EO it belongs to (so that, iff the object's own internal state 
> changes, it can change the EO contents appropriately).
> 
> Is there any way to do that?
> 
> If important, here's the rationale: so far, I have used two distinct 
> attributes, conceptually like this:
> 
> ===
> class DBSomething extends ERXCustomObject {
>   NSData attributeBlob() { storedValueForKey("attributeBlob") } // modelled. 
> Never used directly, but for the cases below
>   MyCustomObject attribute() { new 
> MyCustomObject(attributeBlob,this,"attributeBlob") }
> }
> class MyCustomObject {
>   MyCustomObject(NSData contents, ERXEnterpriseObject owner, String key) {
>     ... ...
>     NSData blobRepresentation() { ... ... }
>     void didChange() { owner.takeStoredValueForKey(blobRepresentation(), key) 
> }
> }
> ===
> 
> but it seems to me it would be cleaner if I could defer creation of 
> MyCustomObject to the ValueFactory, storing the changes to the 
> ValueConversion, and get rid of the ugly dichotomy of foo and fooBlob, 
> removing fooBlob completely and seeing only foo (of type MyCustomObject) at 
> the code level.
> 
> Thanks and all the best,
> OC
> 
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/samuel%40samkar.com
> 
> This email sent to sam...@samkar.com

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to