similar to: Eager loading with inheritance

Displaying 20 results from an estimated 10000 matches similar to: "Eager loading with inheritance"

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 Jun 17
5
STI versus Composition...or the headaches of one big table
Guys, I have a relationship between model classes that I believe is best represented by inheritance, but the likelihood that things will change often is driving us to composition instead. So, I have a class called Autos, and subclasses called Suvs, Minis, Mids, Sports, for example. We have been requested to avoid the STI approach to this, because of fear of a quickly growing table with
2008 Feb 02
1
eager include associated count?
So I know you can eager include associated rows with the :include, but is there a way to include just the associated count? User.find(:all, :select => ''id, first_name, last_name, created_at'', :limit => 30) I want to include user.store.count in the above query. Right now, this gives me an n+1 queries because i get the count for each row. <% for user in @users %>
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 Feb 12
3
Error when Eager Loading "Not unique table/alias"
Hi list, I get the error "Not unique table/alias" (myql 4.1) when trying eager load 2 classes that use the same base class (not STI) Example: <code> class Wedding < ActiveRecord::Base belongs_to :bride, :class_name => ''Person'', :foreign_key => ''bride_id'' belongs_to :groom, :class_name => ''Person'',
2009 Mar 11
12
Eager loading comments associated with user submissions.
Hey everyone, I am working on an application that allows users to submit articles, and also comment on those articles. Pretty much exactly like Digg. Everything works fine except that when there are a lot of comments there are a lot of database queries to both fetch the comments and the users who posted those comments. I have used eager loading in other parts of my application to reduce the
2006 Jun 28
4
Load IDs For Limited Eager Loading
Hi Trying to cut down on queries with eager loading and noticed the following in development.log Load IDs For Limited Eager Loading - SELECT id ....etc Followed by Load Including Associations - SELECT table.id ... etc Is this common practice? What is limted eager loading? Cheers Mark -- Posted via http://www.ruby-forum.com/.
2007 Nov 14
1
New Foxy Fixtures (Rails 2) & STI (Single Table Inheritance)
I''ve got some problems right now using the new model for relationships in fixtures (by label, not by id) and STI. What I''ve got, is a couple of models: Attachment --> FileDownload Version Version has_one file_download with file_download_id on the versions table In my fixtures, I have two FileDownloads in my attachments.yml like so: hemingway_alpha_zip: size: 100
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 Jan 04
1
eager loading and polymorphic associations
There is a dedicated section about eager loading in the docs. A coworker discovered eager loading does not work in polymorphic associations the hard way :-) so I''ve written a patch that documents it: http://dev.rubyonrails.org/ticket/10610 There are at least a couple of tickets that implement something that would change that though: http://dev.rubyonrails.org/ticket/9640
2010 Oct 25
1
A few fixes to eager loading issues
Hey all, I''d really appreciate some eyes on https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5845-activerecord-3-eager-loading-fail#ticket-5845-19. There''s a small issue in Rails 3 eager loading, and this ticket has an accompanying patch. Sssociations that show up twice in a Relation chain like: Article.includes(:comments).includes(:comments =>
2007 Nov 08
0
Dynamic relation with eager loading
A model has 2 columns in its table asset_type_id asset_id the asset_type_id links directly to the table asset_types via a belongs_to asset_types contains a single column ''name'' method_missing in the model says when you call a method matching /^asset.*/ call the corresponding method substituting ''asset'' for the contents of asset_type.name (ie. the name in
2010 Aug 26
0
Eager loading a has_many :through (Rails3)
Hello all, I''ve been trying out Rails 3 and can''t get past this issue: I have a simple has_many :through: class Author < ActiveRecord::Base has_many :author_series has_many :series, :through => :author_series end class Series < ActiveRecord::Base has_many :author_series has_many :authors, :through => :author_series end In my controller I would like to
2005 May 01
0
Eager loading with self associations
Hi, I''m new to ruby on rails and I''m trying to make a self association (as when an employee has a manager, whom is also an employee) work with eager loading on postgres, but the generated sql is wrong the two ends of the association are in the same table (setores), the foreign key is setor_pai and the generated SQL contains this: FROM setores LEFT OUTER JOIN setores ON
2007 Jan 02
0
to_xml eager loading?
Activerecord supports eager loading with the following syntax: Author.find(:all, :include=>[{:posts=>:comments}, :categorizations]. to_xml has an :include option that supports a shallow form of eager loading to create the xml: author.to_xml(:include[:posts]). Is there a way to generate the xml from all associated objects for a particular model instance?
2014 Apr 02
0
Trying to understand eager loading and accessing collections from within instance methods
I'm trying to optimize some of my queries by taking advantage of eager loading. I've created a gist with the specific problem I'm seeing here: https://gist.github.com/tybenz/9944205 Any ideas why the eager loading works for grabbing the collection from the rails console but a SQL query is required when I try to access the collection from inside the instance method? Is there
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
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 Mar 31
2
Eager loading of polymorphic associations
Polymorphic associations work great until I try to do some eager loading through :include. In my example, the interface name is ":imagehaver". Here''s my little eagerly loading find line: Image.find(params[:id], :include => :imagehaver) All it gives me is an ActiveRecord::EagerLoadPolymorphicError with no further explanation. I haven''t been able to dig up anything
2007 Apr 26
1
eager loading not working in production mode
i have an eager load query as such: @groups = ReviewQuestionGroup.find(:all, :conditions => ["review_category_id = ?", @review.category.id], :order => ''review_question_groups.position, review_questions.position'', :include => :questions) in dev mode, this works fine... i get results like @groups[0].questions.length = 13. in production, i