Hi all,
I have a model (Foo) with a has_many association to another model
(Bar). Each Bar backreferences Foo, and calls a method on Foo that is
expensive to call the first time per-instance (Foo#pricey). If all the
instances of Bar referenced the same instance of Foo, the cost of
calling Foo#pricey would only have to be paid once. Alas, this is not
so:
foo = Foo.find :first
foo.object_id
=> 70169390687560foo.bars[0].foo.object_id
=> 70169406714940foo.bars[1].foo.object_id
=> 70169407605180
I haven’t looked into the problem too much, since I thought this was
perhaps a simple, common problem for which solution patterns already
exist. Are there? Alternatively, can you recommend a good starting
point for developing a pattern?
Thanks,
Ian