
Model.all(:links => [:foo, :bar]), the first time it's run, does not initialize the foo and bar associations
Reported by Phil Darnowsky | September 26th, 2008 @ 02:22 AM
This problem seems to arise only the first time the Model.all query is run, so I speculate that it may depend on having a clean identity map.
Run the attached join_models_setup.rb, then join_models.rb. Observe these lines from the end of the output of join_models.rb:
Fri, 26 Sep 2008 07:20:50 GMT ~ debug ~ SELECT "join_models"."id" FROM "join_models" INNER JOIN "model_as" ON ("model_as"."id" = "join_models"."model_a_id") INNER JOIN "model_bs" ON ("model_bs"."id" = "join_models"."model_b_id") ORDER BY "join_models"."id"
Fri, 26 Sep 2008 07:20:50 GMT ~ debug ~ SELECT "join_models"."id" FROM "join_models" INNER JOIN "model_as" ON ("model_as"."id" = "join_models"."model_a_id") INNER JOIN "model_bs" ON ("model_bs"."id" = "join_models"."model_b_id") WHERE ("join_models"."id" IN (1)) ORDER BY "join_models"."id"
Fri, 26 Sep 2008 07:20:50 GMT ~ debug ~ SELECT "join_models"."id" FROM "join_models" INNER JOIN "model_as" ON ("model_as"."id" = "join_models"."model_a_id") INNER JOIN "model_bs" ON ("model_bs"."id" = "join_models"."model_b_id") WHERE ("join_models"."id" IN (1)) ORDER BY "join_models"."id"
[#<JoinModel id=1 model_a_id=nil model_b_id=nil>]
Fri, 26 Sep 2008 07:20:50 GMT ~ debug ~ SELECT "join_models"."id" FROM "join_models" INNER JOIN "model_as" ON ("model_as"."id" = "join_models"."model_a_id") INNER JOIN "model_bs" ON ("model_bs"."id" = "join_models"."model_b_id") WHERE ("join_models"."id" IN (1)) ORDER BY "join_models"."id"
Fri, 26 Sep 2008 07:20:50 GMT ~ debug ~ SELECT "join_models"."id" FROM "join_models" INNER JOIN "model_as" ON ("model_as"."id" = "join_models"."model_a_id") INNER JOIN "model_bs" ON ("model_bs"."id" = "join_models"."model_b_id") WHERE ("join_models"."id" IN (1)) ORDER BY "join_models"."id"
Model A: nil, Model B: nil
Fri, 26 Sep 2008 07:20:50 GMT ~ debug ~ SELECT "join_models"."id", "join_models"."model_a_id", "join_models"."model_b_id" FROM "join_models" INNER JOIN "model_as" ON ("model_as"."id" = "join_models"."model_a_id") INNER JOIN "model_bs" ON ("model_bs"."id" = "join_models"."model_b_id") ORDER BY "join_models"."id"
[#<JoinModel id=1 model_a_id=1 model_b_id=1>]
Fri, 26 Sep 2008 07:20:50 GMT ~ debug ~ SELECT "id" FROM "model_as" WHERE ("id" IN (1)) ORDER BY "id"
Fri, 26 Sep 2008 07:20:50 GMT ~ debug ~ SELECT "id" FROM "model_bs" WHERE ("id" IN (1)) ORDER BY "id"
Model A: #<ModelA id=1>, Model B: #<ModelB id=1>
Observe the last 7 lines of the output. Note that both SQL queries execute the join properly, but only the second one actually selects the join columns as well, and thus only the second one populates the association properly.
Comments and changes to this ticket
-
Phil Darnowsky September 26th, 2008 @ 02:23 AM
- no changes were found...
-
Phil Darnowsky September 26th, 2008 @ 10:20 AM
This may be related or identical to ticket #444: http://wm.lighthouseapp.com/proj...
-
Dirkjan Bussink September 27th, 2008 @ 07:42 AM
Could you please test whether this is fixed now? I think it's the same bug as #444
-
-
Dirkjan Bussink October 7th, 2008 @ 02:51 PM
- State changed from new to resolved
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »