On Monday, August 18, 2014 1:57:08 AM UTC-7, Frederick Cheung wrote:
>
>
> On Monday, August 18, 2014 2:57:05 AM UTC+1, Phil wrote:
>>
>>
>> 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.
>>
>>
>> Not that I know of. As of rails 4 (or is it 3.2?) the generated 
> association accessors are defined in a module (rather than directly on the 
> class so it's easy enough to override them so you could do
>
> class TestParent
>    has_many :test_children
>
>    def test_childen(force_reload=true)
>      super(force_reload)
>    end
> end 
>
> To change it for all associations without having to do this on a per 
> association basis would probably require some monkey patching inside the 
> activerecord code - sounds brittle.
>
> As tamouse says if you use build/create on the association then you won't 
> see this behaviour, although there can still be differences between the 
> array thus constructed in memory and the array you'd get if you had 
> selected from the database (for example if you have an order clause on the 
> association, custom select  etc.)
>

Ah, yes, I see it now in 
activerecord-4.0.8/lib/active_record/associations/collection_association.rb

OK, makes sense.  I've love to have that be a config option I could throw 
in the environments config files to turn that off, if needed.


> Rails has been like this at least since the 1.0 days - I can't say I've 
> ever run into particular issues from it.
>

In my case it was rather nasty.  It went something like this:

@order = Order.new ...
... record line items..
@order.line_items... calculate subtotal to calculate tax and record that as 
the final line item
run charge on credit card, render receipt page, send mailers, etc.

The result was the customer got receipt page/emails and charged without 
tax!  Fulfillment and Accounting pulling up the order would confusingly get 
the right total and tax.

Thanks, I have a much better understanding of what's going on now.


Phil

-- 
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/319cce88-0041-4a95-9062-1e0cdd80373d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to