I have a model Foo which :has_many bars, initially I create and save a Foo instance called foo. Looking at foo.bars it is empty as expected. But after I create a bar instance that belongs to the foo instance. foo.bars should no longer be empty but it still it. If I do Foo.find(foo.id).bars it returns a non-empty result as expected. Is there a way to update foo so that I don’t have to do that. Thanks!
I have a model Foo which :has_many bars , initially I create and save
Share
The problem is that foo.bars would have been cached by the first call. You can force it to refresh using
foo.bars(true)