Find on rails model also automatically finds it's has_one association in
the rails console
I'm using rails 3.2.11 and I have a Customer model and it has_one
:referral_code. If I execute Customer.find(316) in the rails console I get
the following results:
>> Customer.find 316
=> Customer Load (0.3ms) SELECT "customers".* FROM "customers" WHERE
"customers"."id" = $1 LIMIT 1 [["id", 316]]
=> ReferralCode Load (0.2ms) SELECT "referral_codes".* FROM
"referral_codes" WHERE "referral_codes"."customer_id" = 316 LIMIT 1
Why does it automatically also load the ReferralCode model? It may not
have anything to do with the :has_one association, but if I comment that
line out of my customer model it won't load the ReferralCode. I've used
many other :has_one associations before, but have never found it loading
them automatically. Any pointers as to what's happening will be much
appreciated.
I searched my production log and it doesn't seem to be happening there so
this may be just console related.
No comments:
Post a Comment