similar to: Eager loading a has_many :through (Rails3)

Displaying 20 results from an estimated 30000 matches similar to: "Eager loading a has_many :through (Rails3)"

2010 Feb 14
2
has_many :through eager loading only loading one record
Hello, I''ve been using Rails for years, including has_many :through and eager loading, but this one has me stumped. The problem is that Active Record is only eager-loading the first of many records. Here are the models (note set_table_name for a legacy schema): class Tag < ActiveRecord::Base set_table_name ''tag'' end class DishTag < Tag has_many
2008 May 08
1
Eager loading of association extensions
Hello all, Is it possible to do eager loading of association extensions? That is, the following code produces one SQL query: cat = ProductCategory.find(:first, :include => :pricing_rules) cat.pricing_rules But if in ProductCategory I have an association extension like this: has_many :pricing_rules do def applicable() find(:all).select(&:applicable?) end end the
2010 Aug 05
3
how to ? Rails 3 ActiveRecord eager loading and AREL
Hello everyone, I would like to eager load scoped records to avoid queries executed in a loop (huge performance impact). The "scoped" part is what is giving me a hard time. I''m using Rails3 RC. Does anyone have any idea how I can do it? Here is a test case : we have an "Article" and a "Comment" Activerecord models, article has many comments comment
2006 Oct 08
1
Two-way eager loading?
My problem is that I have two classes where the eager loading isn''t working as well as I would hope... Here are my two classes: class Daynote < ActiveRecord::Base belongs_to :userplace class Userplace < ActiveRecord::Base has_many :daynote, :dependent => true When I show my userplaces, I want to get the associated daynotes with them, so I am doing: @userplace =
2006 Jul 31
0
Patch for #3438: Eager loading doesn''t respect :order of associations
Hello all, I still have a patch for #3438 (eager loading doesn''t respect association orders); it passes all unit tests, and has additional unit tests with full coverage. The patch is attached. == The Bug == Author.find(1).posts != Author.find(1, :include => [:posts]).posts if Author has_many :posts, :order => anything. This means that either one must avoid eager loading or
2006 Aug 16
1
using :select with :include to limit eager loading
Activerecord''s find option `:select'' does not appear to work when :include is used to eager load associations. However, I sometimes want to perform ready-made joins on associations to limit the results of a query. here''s a simple example: table university: STRING code INT id table term: STRING name INT university_id INT id the associations of the models
2005 Jul 14
1
Single-table inheritance and eager loading
I have a people table with four types of people: clients, spouses, children, and others all setup using single-table inheritance with a foreign key back to a household record. A Household has_one client and spouse, and has_many children and others. I want to use a single "Household.find(@session [:household_id], :include => [:client, :spouse, :children, :others])"
2006 Jan 31
4
Rails bug? Conditions on associations ignored by eager loading
I''m looking for someone to confirm the following as a bug in Rails 1.0 before I post it to Trac. If I use eager loading on an association that has conditions defined, the conditions are ignored. The following example illustrates the problem. I have two tables: create_table "blogs", :force => true do |t| t.column "name", :string end create_table
2007 Mar 09
0
Eager loading with inheritance
In order to implement inheritance (STI was not ideal), I have implemented a solution similar to what is described in this post: http://www.ruby-forum.com/topic/73822#108686. I have one model that acts as a parent class with shared attributes, two child models with different attributes, and a module that contains shared functionality for the child models. The issue arises in creating associations
2006 Aug 04
2
problem eager loading with sti
Here''s the setup (working off Rails 1.1.4): Class Project belongs_to :employee Class Employee < Person has_many :projects When I try to paginate(:employees, :include => :projects) I get the error "Association named ''projects'' was not found; perhaps you misspelled it?" I can :include other models that the Person class has_many or habtm of, and if I
2008 Sep 16
3
has_one :through eager-loading problem
I have a problem with the :include option in find for my has_one :through association. I have Users, Profiles and Customers, all connected to each other with a has_one :through => :membership association like this: class Profile < ActiveRecord::Base #could also be user or customer has_one :membership # i saw an acrticle of Ryan about has_one :through, there this would be has_many, is
2006 Sep 26
0
ActiveRecord, has_many association and object graphs
I am still using Rails 1.0... I have a simple has_many association: class Round < ActiveRecord::Base has_many :scores end class Score < ActiveRecord::Base belongs_to: round end When I do something like this (contrived for the sake of clarity): rr = Round.find(params[:id]) rr.scores.each { |s| logger.debug("object_id=#{s.round.object_id}") } I see a database query on
2007 Jan 29
3
Eager Loading: Stacking Includes?
Is it possible to stack :include''s in a situation like this: A has_many Bs B belongs_to A B has_many Cs C belongs_to B The result of the query looking something like... A.id B.id C.id 0 0 0 0 0 1 0 0 2 0 1 0 ... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you
2009 Oct 08
6
Eager Loading a Relationship That Has No PK/FK
I''m attempting to wrestle an old DB into Rails. This relationship is giving me trouble: class Show < AR::Base has_many :segments end class Segment < AR::Base belongs_to :show has_one :media #this has no PK/FK relation end A Segment is "linked" to Media by Media.name, which is the result of concatenating Segment.name and Segment.part. As I said there are is no
2006 Mar 13
4
Find and eager loading questions
Hi all, I want to see if I''m not missing something with associations and eager loading. (I''m currently using Locomotive on OS X and SQLite3.) I have two simple tables/models, set up properly: teams has_many :matches and matches belongs_to :teams. Matches has a match number and a team_id field (along with several other fields) and teams has a team_number field (again, along with
2007 Mar 27
7
Eager loading not working well for me
Man my app is causing me so much grief lately. Okay let''s say I have: class Discussion has_many :posts end class Post belongs_to :discussion acts_as_tree end Then let''s say I grab a discussion object and try to eager load all of its posts: discussion = Discussion.find(:first, :include => [:posts]) Seems simple enough and it grabs an entire tree of posts. However:
2006 Feb 14
0
Help with Eager Association
I''ve gotten eager associations to work before, but for some reason this isn''t working out for me this time. I''ve been scratching my head but can''t quite figure out the nuances of what works and what doesn''t work. I''ve got 3 models: profile, widget_configuration and widgets profile.rb -- has_many :widget_configurations
2006 Sep 03
1
New Technique: Subsets of has_many Associations
I just now thought of this, and sure enough it works like a charm (at least so far in my limited testing): has_many :events, :dependent => :delete_all has_many :upcoming_events, :class_name => "Event", :conditions => "date > NOW()" The purpose of this is that it makes eager loading of subsets of associations possible without replacing all the magic of the
2006 Aug 07
1
Eager loading wierdness
Consider this problem. I have an Item that has_many Features I want to find all Items with a Feature name of ''foo''. Normally you would do this.. @items = Item.find(:all, :conditions=>["features.name = ?", ''foo''], :include=>:features) This all works fine and dandy except for this problem. If you do this... <% for item in @items %>
2006 Sep 05
2
Eager loading and :order produces ambiguous column error
I''m sure I saw a post about this topic a while ago, but I haven''t been able to find it again. I have this association: has_many :sections, :class_name => "QuestionnaireSection", :order => "position", :dependent => :destroy, :include => :questions but since the Question object has a position column, the query comes back with Mysql::Error: