That makes sense to me, although it looks like what should happen before 
your change is that

https://github.com/jeremyevans/sequel/commit/de183ed7ac6ad8df5353f54be9579350977d1c16#diff-0cd793d48726eacb1a6cb8af71e125a4L2602
 
removes the reciprocal object and then
https://github.com/jeremyevans/sequel/commit/de183ed7ac6ad8df5353f54be9579350977d1c16#diff-0cd793d48726eacb1a6cb8af71e125a4L2606
 
adds the same object back

...so I'm trying to figure out why that didn't happen.

Or am I misunderstanding that bit of code?

On Thursday, December 13, 2018 at 11:22:37 AM UTC-8, Jeremy Evans wrote:
>
> On Thursday, December 13, 2018 at 10:01:57 AM UTC-8, Ben Alavi wrote:
>>
>> This does fix the issue for us because we are so far only referencing the 
>> reciprocal association in the validate method, however I think there is 
>> still an issue with the reciprocal association being cleared that is not 
>> present for other association types.
>>
>> I updated the gist to reproduce:
>>
>> https://gist.github.com/benalavi/20817b785a08d16912f82ce31afde029
>>
>> The one_to_one association (cover) is now validated only once, however 
>> the reciprocal association (album) is present when validate is called, but 
>> then is nil when after_save is called. I would guess that this could cause 
>> issues especially since it doesn't happen for the one_to_many association.
>>
>> Output of the gist w/ the validation fix:
>>
>> create Album + one_to_many Artist + one_to_one Cover
>> #<Artist:0x007f52c4b688e8> validate #<Album:0x007f52c4b6b890>
>> #<Cover:0x007f52c51e5b30> validate #<Album:0x007f52c4b6b890>
>> #<Artist:0x007f52c4b688e8> after_save #<Album:0x007f52c4b6b890>
>> #<Cover:0x007f52c51e5b30> after_save #<Album:0x007f52c4b5ce08>
>> create Album
>> update Album + one_to_many Artist
>> #<Artist:0x007f52c52018a8> validate #<Album:0x007f52c5203bf8>
>> #<Artist:0x007f52c52018a8> after_save #<Album:0x007f52c5203bf8>
>> update Album + one_to_one Cover
>> #<Cover:0x007f52c520fd18> validate #<Album:0x007f52c5203bf8>
>> #<Cover:0x007f52c520fd18> after_save 
>>
>> ^ In that last line the album reference is nil
>>
>
> I think in this case when nested attributes is used, if the current 
> object's associated value matches the setter method value, then we can skip 
> unsetting the reciprocal association before saving the associated object.  
> I've implemented that and it does appear to fix the issue: 
> https://github.com/jeremyevans/sequel/commit/de183ed7ac6ad8df5353f54be9579350977d1c16
>
> Not sure if that is the best way to handle it; I'm open to other 
> suggestions.
>
> Thanks,
> Jeremy
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to