On Thursday, October 24, 2013 7:02:32 AM UTC-7, Jeremy Evans wrote:
>
> On Thursday, October 24, 2013 2:20:40 AM UTC-7, Sean West wrote:
>
>> I am using Sequel to access the database for an API server. I am using
>> Sequel 4.3.0 with a PostgreSQL 9.1 database.
>>
>> Through the API, foreign keys on tables may be updated. It seems that
>> Sequel does not automatically reload the association cache when the foreign
>> key is updated and I'm curious if there is any way to do this.
>>
>> For example:
>>
>> irb(main):003:0> r = Roster.first :id => 153
>>> => #<Roster @values={:id=>153, :player_id=>44}>
>>> irb(main):004:0> r.player
>>> => #<Player @values={:id=>44}>
>>> irb(main):005:0> r.player_id = 46
>>> => 46
>>> irb(main):007:0> r.player
>>> => #<Player @values={:id=>44}>
>>
>>
>> Saving the record doesn't seem to force the association cache to clear
>> either.
>>
>> It is not until I either call r.player(true) or delete the association:
>>
>> irb(main):012:0> r.associations.delete :player
>>
>>
>> that the association is reloaded.
>>
>> Is there any feature built into the library to automatically accomplish
>> this? or a plugin? I saw something in the association docs which *appears*
>> to hint at such a feature, but I couldn't see any other details on it:
>>
>> autoreloading_associations [R]
>>>
>>> Hash <http://sequel.rubyforge.org/rdoc/classes/Hash.html> with column
>>> symbol keys and arrays of
>>> #many_to_one<http://sequel.rubyforge.org/rdoc/classes/Sequel/Model/Associations/ClassMethods.html#method-i-many_to_one>association
>>> symbols that should be cleared when the column value changes.
>>
>>
>> I'd like this to apply across all of my models.
>>
>> Thanks for the awesome library!
>>
>
> Sequel should do this by default starting in version 4.0. Before 4.0, you
> could use the association_autoreloading plugin to accomplish the same
> thing. If this isn't working for you, please post a small, self-contained,
> single file example that shows the problem. You may also want to post the
> output of:
>
> p Roster.autoreloading_associations
>
> Thanks,
> Jeremy
>
Thanks for pointing me in the right direction. Turns out I was using an
older version of Sequel. It works as you mentioned in 4.3.0.
Sorry for the trouble!
--
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 http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.