similar to: Trying to understand eager loading and accessing collections from within instance methods

Displaying 20 results from an estimated 3000 matches similar to: "Trying to understand eager loading and accessing collections from within instance methods"

2006 Mar 20
2
Noob Understanding Collections
Okay, I''ve had some success rendering partials and felt I''d try something more interesting with collections. I have a query run by my model, which works. When I run it from the console I can see all of the data I want. However, bringing that into my view isn''t working the way I think. So obviously I''m thinking wrong, but I can''t see where my
2006 Jun 02
1
controller instance methods available in rhtml?
In rhtml, you have access to controller. I am trying to set an instance var in my controller, then retrieve it in my form display. I know I could do this through one of the hashes I have access to, but I''m trying to understand why I can''t do it this way. No matter what, when I try to output from my rhtml either <%= controller.whynot || ''Unknown'' %> or
2006 Feb 27
1
Instance methods in runner?
I am having a devil of a time with some runner actions. I can not seem to call any instance methods on found records. Even when I strip is down to the basics: def self.deliver self.find(:all, :conditions => ["#{Message.table_name}.status = ?", ''pending''], :include => [:site, :template]).each {|m| logger.info m.is_recurring? # my method logger.info
2010 Jan 16
0
Extending instance-methods of an Module for Plugin-Development
Don''t know if i should write this to rails or ruby mailinglist. But in the case i wan''t to extend the facebooker-plugin without touching it, i will here. 1. Instance-Methods of modules? The methods in a module may be instance methods or module methods. Instance methods appear as methods in a class when the module is included, module methods do not. Conversely, module methods may
2007 Nov 20
2
Plugin: create instance methods dynamically in ClassMethods?
Hi all I have the following plugin code: module IncenseCrud def self.included(base_class) base_class.extend(ClassMethods) end module ClassMethods def performs_incense_crud def index list return render(:action => ''list'') end end end end In init.rb I have the following: require File.dirname(__FILE__) +
2006 Apr 08
2
ActionView::Helpers::FormHelper instance methods should take an object reference rather than an object_name.
Hi ActionView::Helpers::FormHelper methods (e.g. #text_field, #check_box...) take object_name as an argument. From this argument they infer a name that is supposed to contains the reference to the relevant object. I can''t see why the FormHelper methods were designed that way. Compared to simply passing them a reference, the current way seems too complicated and an invitation to problems
2008 May 21
3
How to access Rails::Configuration instance methods
There was a thread yesterday about ENV["_"] which is not available to Windows, I got to playing around with how to find access to the initializer_path or in this case the root_path My question is more about why I don''t have access to what appears to be a public method than finding the root_path. I did this in 2.0.2 with script/console The Rails object has a Configuration
2007 Feb 12
0
[867] trunk/wxruby2/doc/textile/log.txtl: Fix methods section, organise instance and class methods
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding:
2006 Jan 19
0
Limited eager loads and conditions on the eager tables
Hi, Why are limited eager loads and conditions on the eager tables incompatible? Doing a find(:all) without :include causes a select * query to be generated, which means the id fields everwrite each other if associated tables are included using :joins. But using :include, if conditions are placed on the tables listed in :joins then Rails throws an exception when :limit is included too.
2006 Dec 19
9
Stubbing ActiveRecord Models gets very difficult with instance methods
I have seen some basic examples of using Mocha and Stubba with ActiveRecord Models; However, the ones I read were somewhat simplistic. That is they stubbed the find class method of the model, or the execute method of the connection object. While stubbing the find method had the desired effect for the author it did not help with a situation I was hacking away on. Which was writing a test case
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
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 Jul 03
0
Eager loading of ''is meant to be nil'' Associations
If I ''find'' using :include, and some included associations are null, then looping through the array executing ''if obj[i].assoc'' accesses the database for a second time (as obj.assoc is nil). eg Topic, has_many posts Post has_one email and posts = Post.find(:all, :condition => ''posts.topic_id = 10'', :include =>
2006 Jun 19
0
Eager loading and acts_as_tree
Hi all, I have a node structure which acts_as_tree. I am pulling the first two levels under the root node with: @root = Node.find(1, :include => [ { :children => [ :children, :parent ] }, :parent ]) How do I pull out the first three levels? What about four? @root = Node.find(1, :include => [ { :children => [ { :children => [:children, :parent] }, :parent ] }, :parent ])
2006 Mar 01
1
Eager loading problem. Help greately appreciated
Each Timesheet has an employee. An employee has a division and a location. I want to find all the timesheets with a status of 2. I then iterate over the timesheet collection and print the timesheet name, employee name, employee divison name, and employee location name. Like so: for t in Timesheet.find(:all,:conditions=>"status=2",:include=>:employee) puts timesheet.date
2006 Mar 14
3
cascading eager loading patch not working in oracle
Notice the "AS" keyword appears many times. Oracle does not support this keyword: ActiveRecord::StatementInvalid: OCIError: ORA-00905: missing keyword: SELECT tim esheets.id AS t0_r0, timesheets.start_date AS t0_r1, timesheets.status AS t0_r2, timesheets.cost AS t0_r3, timesheets.charge AS t0_r4, timesheets.employee AS t0 _r5, employees.id AS t1_r0, employees.name AS t1_r1,
2006 Mar 26
0
Eager loading and polymorphic association
Hi all, Is it possible to do "eager loading" with polymorphic associations ? Ex : I have a Page model that acts as taggable. When I do Page.find(:all), I would like to retrieve all tags associated with a page. Thanks, Thomas. -- Posted via http://www.ruby-forum.com/.
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
2006 Feb 10
1
Eager loading issue
I have three tables, Invoices, Projects, and Managers. Each manager has many projects. Each project has many invoices. When displaying a list of the invoices, I am using: Invoice.find(:all, :include => [:project]) Since the list shows information from the project table. (For example, a table showing Invoice Date, Project Name). However, I''d also like to show the manager name.
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'',