ruby - Padrino + FactoryGirl not performing Lazy Loading -
i'm developing thesis on padrino, using active record orm , factorygirl mocking framework.
i'm facing strange behavior.
i've 2 models: user , rate.
- user has 'has_many :rates' association; - rate has 'belongs_to :user' association; - 'rates' table has integer attribute named 'user_id' (not created 'references' on migration, directly 'integer').
my association working well, after performing reload on parent object.
here snippets related issue: https://bitbucket.org/snippets/cuscos/mbdak
if start 'padrino console' , create user manually, current behavior:
$ user = factorygirl.create(:user_with_rates) $ user.rates.length # received '0', expected '1' $ user.rates.all.length # received '1', ok $ user.reload! $ user.rates.length # i'm receiving '1' correctly
it seems activerecord isn't performing lazy loading reason.
does know why happening?
thanks support far.
for may interest, here solution i'm adopting solve problem:
in user factory, instead:
after(:create) |user, evaluator| create_list(:rate, evaluator.rates_count, user: user) end
do:
after(:create) |user, evaluator| user.rates << create_list(:rate, evaluator.rates_count, user: user) end
it's not proper solution, solved problem now.
cheers o/
Comments
Post a Comment