Anton Anykeyev
2010-Dec-13 21:00 UTC
"Load Including Associations" and "create_time_zone_conversion_attribute?"
Hi there. I''ve got a very nasty problem with loading objects in Rails 2.3.5 I want to preload a set of objects with their associations. I''m trying to do something like that: @members = Guildsman.find(:all, :include => [{:roster_items => :roster},{:gm_lineups => :lineup}], :conditions => [''lineups.name<>?'',''zzz'']) with this i''m getting SQL-query: Guildsman Load Including Associations (3.0ms)[0m [0m SELECT "guildsmen"."id" AS t0_r0, "guildsmen"."name" AS t0_r1, "guildsmen"."user_id" AS t0_r2, "guildsmen"."mol" AS t0_r3, "guildsmen"."created" AS t0_r4, "guildsmen"."accepted" AS t0_r5, "gw_roster_items"."id" AS t1_r0, "gw_roster_items"."roster_id" AS t1_r1, "gw_roster_items"."gm_id" AS t1_r2, "gw_roster_items"."char_id" AS t1_r3, "gw_roster_items"."penalty" AS t1_r4, "gw_roster_items"."created_at" AS t1_r5, "gw_roster_items"."updated_at" AS t1_r6, "gw_rosters"."id" AS t2_r0, "gw_rosters"."doc_id" AS t2_r1, "gw_rosters"."dt" AS t2_r2, "gw_rosters"."gwtype" AS t2_r3, "gw_rosters"."created_at" AS t2_r4, "gw_rosters"."updated_at" AS t2_r5, "guildsmen_lineups"."id" AS t3_r0, "guildsmen_lineups"."lineup_id" AS t3_r1, "guildsmen_lineups"."gm_id" AS t3_r2, "guildsmen_lineups"."dt_start" AS t3_r3, "guildsmen_lineups"."dt_end" AS t3_r4, "guildsmen_lineups"."created_at" AS t3_r5, "guildsmen_lineups"."updated_at" AS t3_r6, "lineups"."id" AS t4_r0, "lineups"."codename" AS t4_r1, "lineups"."name" AS t4_r2, "lineups"."fee" AS t4_r3, "lineups"."created_at" AS t4_r4, "lineups"."updated_at" AS t4_r5 FROM "guildsmen" LEFT OUTER JOIN "gw_roster_items" ON gw_roster_items.gm_id = guildsmen.id LEFT OUTER JOIN "gw_rosters" ON "gw_rosters".id = "gw_roster_items".roster_id LEFT OUTER JOIN "guildsmen_lineups" ON guildsmen_lineups.gm_id = guildsmen.id LEFT OUTER JOIN "lineups" ON "lineups".id "guildsmen_lineups".lineup_id WHERE (lineups.name<>E''zzz'') and then in view i use: <%@members.each do |gm|%> ... <%=gm.gm_lineups.last.lineup.name%> ... <%end%> The first time it works perfect by on the very first refresh of the page i''m getting an error with such stack: C:/programs/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:142:in `create_time_zone_conversion_attribute?'' C:/programs/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:75:in `define_attribute_methods'' C:/programs/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:71:in `each'' C:/programs/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:71:in `define_attribute_methods'' C:/programs/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:351:in `respond_to?'' C:/programs/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/associations/association_proxy.rb:213:in `method_missing'' D:/work/aptana/tax/trunk/app/views/cadre/gw_roster/index.html.erb:18:in `_run_erb_app47views47cadre47gw_roster47index46html46erb'' D:/work/aptana/tax/trunk/app/views/cadre/gw_roster/index.html.erb:11:in `each'' D:/work/aptana/tax/trunk/app/views/cadre/gw_roster/index.html.erb:11:in `_run_erb_app47views47cadre47gw_roster47index46html46erb'' If i remove the :conditions part of select like that: @members = Guildsman.find(:all, :include => [{:roster_items => :roster},{:gm_lineups => :lineup}]) then i''m getting several different queries for this select: [4;35;1mGuildsman Load (0.0ms)[0m [0mSELECT * FROM "guildsmen" [0m [4;36;1mGwRosterItem Load (1.0ms)[0m [0;1mSELECT "gw_roster_items".* FROM "gw_roster_items" WHERE ("gw_roster_items".gm_id IN (5,6,8,9)) [0m [4;35;1mGuildsmanLineup Load (0.0ms)[0m [0mSELECT "guildsmen_lineups".* FROM "guildsmen_lineups" WHERE ("guildsmen_lineups".gm_id IN (5,6,8,9)) [0m [4;36;1mLineup Load (1.0ms)[0m [0;1mSELECT * FROM "lineups" WHERE ("lineups"."id" IN (1,4)) [0m and then everything works pretty well i guess that Rails can''t properly populate objects with data from single query but i can''t understand how to fix it. Will be grateful for any information. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.