On Sun, Aug 17, 2014 at 8:57 PM, Phil <[email protected]> wrote:

>
> I hate to reply to myself, but I narrowed it down to Rails caching by
> DEFAULT of model queries.  It can be worked around by passing 'true', like
> this:
>
>
> tc.name = "something different"
>
> tc.save!
>
> tp.test_children.map {|x| x.name }.to_sentence # => "test1, test2, test3,
> and test4" *WRONG*
>
> tp.test_children(true).map {|x| x.name }.to_sentence # => "test1, test2,
> test3, and something different" *CORRECT*
>
>
> Another workaround is to just stop using has_many and such in favor of
> manual functions, a la:
>
>  def test_children
>
>   return TestChild.where(["test_parent_id = ?", self.id])
>
>  end
>
>
> Is there a way to turn this sort of caching off globally?  (Other caching
> is fine, I don't want to turn all caching off.)
>
>
> BTW- It is a bit mind blowing that this is turned on by default.  Possible
> data corruption shouldn't ever be preferred by default over (possible)
> speed gains.  I'd still categorize this as a serious bug, at least as a
> configuration default.
>
>

Try tp.reload after you make a change in the collection the way you have
been. If you had been building your children entries as:

tp.children.create(name: "test1")

tp would be fully cognizant of all it's children.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: 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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAHUC_t-sODAxSDWHuSc92ab47%3DYLxhvLp1k7JR-bL0F1Q4fg1g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to