similar to: Eager loading not working well for me

Displaying 20 results from an estimated 20000 matches similar to: "Eager loading not working well for me"

2006 Sep 13
1
Eager loading with acts_as_tree
So I have a model that acts_as_tree and I run a method on a collection of all of these records. This method walks the tree and fetches the parent/children, etc. This results in many, many duplicate SQL queries to be executed. Is there a way to eagerly load all of these models? Something along the lines of: Model.find(:all, :include => [:children, :parent]) If I execute the above statement, I
2007 Feb 14
3
eager loading parents and children (acts_as_tree)
I am struggling with how to do eager loading of an acts_as_tree model. If the model Stuff acts_as_tree I know I can do this to get children as well: Stuff.find(:all, :include => :children) But what if the model I am including is the one that acts_as_tree? For example, say Picture belongs_to Category. Category acts_as_tree and I want to get all pictures that are members of a category that
2007 Dec 20
3
ActiveRecords Eager Loading
Hi, I am doing an eager loading in ruby on rails using below statement ------------------------ Article.find(:all, :include => [:asset, :vote], :conditions=>"assets.parent_id is null", :order=>"stat_final_ranking desc", :limit=>20) --------------------------------------- the above statement resulted in this expensive query.
2006 Jun 16
1
sortable acts_as_tree with heirarchy
I''ve been stumbling on the tut at oriontransfer (http://wiki.oriontransfer.co.nz/main/show/SortableTree) I''ve got it working in a one dimensional list and I''ve got the drag and drop working on children, but as can''t get it to save the tree. Here''s my view: <h2>Menu Prototype 2</h2> <%= flash[:notice] %> <ul
2006 Mar 21
5
Order records based on number of children
Let''s say I have simple schema with two tables. The models are defined like the folllowing: class Parent < ActiveRecord::Base has_many :children end class Child < ActiveRecord::Base belongs_to :parent end Simple has_many relationship. Is there any way to order the results of a Parent.find_all by the number of children the parent has? I can sort with sorted_parents =
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 Jul 03
13
Eager loading ActiveRecord objects
I have a complex graph of ActiveRecord entities that I want to load with one big honkin'' join query to avoid ripple loading. It''s for a report. However :include doesn''t get me all the way there because I want to load parents of parents (or children of children). I don''t mind doing the SQL by hand but I''m not quite sure what to do to get the result
2006 Jul 22
7
Validation with has_many
I have two problems. I have a comment that has_many uploads. Before saving the comment, I want to be sure that the upload(s) has passed validation, but I also need to validate in other ways. For example, I do not want to save the comment if there is no comment or upload. Or, I do not want to save the comment if the image has been uploaded previously (comparing md5s with past upload md5s
2005 Sep 23
6
problem with acts_as_tree
Hi, I''m using the latest gem version of rails under MacOS Tiger. I was trying to use acts_as_tree as described in the rails book. So I have something like: class Category < ActiveRecord::Base acts_as_tree :order => "title" end create table categories ( id int not null auto_increment, title
2008 Jan 02
1
wants to get all parents with no children, etc
To all: hi, i have implemented the associations in my models so i have a Parent model that has many Children model but i need to get a list of Parents that do not have children or Parents that have just 2 children or Parents that have children whose name is ''James'', or ''Sarah'', or ''Betty'' or Parents whose children do not have names like
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
2008 Jul 11
1
Using custom routes to handle new nested resources
I have a couple of resources, one nested in the other, such that my resource spec in routes.rb is: map.resources :parents, :has_many => :children This will generate a route for a new child that assumes that the parent has already been saved, something like: /parents/:parent_id/children/new But what if I want a route that handles the case where the parent resource is also new, and thus
2007 Feb 26
24
Ruby/rails port of Cocoon/hibernate
Hi, I''m currently running an apache/jboss cocoon/flow/hibernate/ajax paypal (directpayment) project and am looking into the possibility of porting it across to ruby/rails. For that reason I would like to know the following: 1. Can I call my java classes or would I be looking at a complete rewrite in ruby? 2. How effective is ruby in terms of seperation of concerns regarding design from
2006 Jul 24
3
HowTo?: Eager caching of third order ActiveRecord assoc.
Hello. Using the ":include", which generates a "LEFT OUTER JOIN" SQL command, it is possible to eagerly preload second order data objects (children) for a given association. I wanted to know, if it is possible to eagerly preload and cache third order (or more) data objects, which are little-children or little-little-children. As I''ve seen. it is possible to add
2006 Jan 05
2
Confused...
Ok, So, I''ve got two data tables associated through a foreign key. class Child < ActiveRecord::Base belongs_to :parent, :class => Parent, :foreign_key => "parent_id" # also has attr1, attr2 end class Parent < ActiveRecord::Base has_many :children, :class => Child, :foreign_key => "parent_id" end So, I''m trying to build the new/edit
2006 Feb 14
8
Assigning has_many child in parent creation question
If I have... class Parent has_many :children end class Child belongs_to :parent end ...then... * Assigning a _new_ child during parent''s creation saves the child record with the parent''s id. child = Child.new Parent.create(:children => [child]) # Results in child being associated with parent * Assigning an existing child after a parent''s creation
2006 Mar 25
2
acts_as_tree wierdness with children.count and children.size
i am making a category tree and i iterate over the category using my counter_cache however it would show a different number than what was actually being represetned in the tree. Here is an example cat.children = [cat2, cat3] puts cat.children.size 2 puts cat.children_count 2 cat4.parent_id = cat.id cat4.save puts cat.children.size
2006 Jun 07
2
destroy on has_many relationships.
i need to delete a record from the database and delete all of it''s children as well. is there a method for this? right now, i am finding all the children with the parent_id and destroying them first and then destroying the parent. seems like there would be a better way to do this but i can''t seem to figure it out. thanks, josh -- Posted via http://www.ruby-forum.com/.
2006 Jul 18
4
Limiting markdown/textile
I''m using RedCloth for a forum type app. I want users to have control over the look of their posts, but within limits. For example, I don''t want them to be able to include images or use header tags. The RedCloth documentation is pretty thin and I don''t feel it''s very explanatory. I''m wondering if there''s any easy way to do this? Or do I
2005 Apr 19
3
Rails 0.12.1: No major update without a bit of pain
There''s nothing like pushing a new major update in order to find bugs in the code when its exposed to a couple of hundred working applications. Thankfully the fixes were almost as swift as the reports. In any case, you''ll _definitely_ want to upgrade to 0.12.1 right away. There''s a good handful of fixes for both Action Pack and Active Record (mostly concerning the