similar to: Overwriting / Decorating ActiveRecord association accessor

Displaying 20 results from an estimated 200 matches similar to: "Overwriting / Decorating ActiveRecord association accessor"

2007 May 28
2
Rails, respond_to? over anonymous module (extend has_many).
Hello List, I''m trying to generate examples for some list-helpers I have coded which use in my projects. Basically, the Playlist class uses one anonymous module in has_many that acts as helper between acts_as_list and my desired API: class Playlist < ActiveRecord::Base # associations go here has_many :playlist_items, :order => :position, :dependent => :destroy has_many
2009 Aug 28
2
Association extension method
In my application a user working at a dropzone can manipulate transactions against customer accounts. Here''s my models: class Transaction < ActiveRecord::Base belongs_to :account end class Account < ActiveRecord::Base belongs_to :dropzone has_many :transactions end class Dropzone < ActiveRecord::Base has_many :transactions, :through => :accounts do def
2007 Jan 31
1
help with extensions
I am working with extensions to has_many associations, and I want to create a finder method that is conditional on the attributes of the object whose association I''m working with. So, to use the example from the Agile Web Development: the authors show on pg 340 in the second edition how to pass an argument to a finder method. But I want to know if it''s possible to instead have
2009 Jul 20
2
Hitting unknown error with "can't dup NilClass"
Hi, My system has been encounter this problem, and I couldn''t find solution after debugging. My scenario is stated below: class user has_many :posts has_many :comments end class post belongs_to :user has_many :comments, :as => :commentable end class comment belongs_to :post belongs_to :user end For this case, I am trying to retrieve each post''s comment
2012 Nov 09
1
decorating API in R
How best to implement a decorator pattern in R? What I mean, why I ask: A group of ncdf4 users is trying to make it easier (notably for ourselves :-) to write correctly IOAPI-formatted netCDF. Since IOAPI http://www.baronams.com/products/ioapi/ decorates netCDF, one obvious way to do a package=ioapi is to decorate the netCDF API from package=ncdf4. E.g., to add a data variable (datavar) with
2006 Apr 06
4
Record retrieval in Many-to-many using :through not working
Hello, I get an error while retrieving records from the following model structure. Tables foods - id, food foodallergies - food_id, symptom_id, a few other columns symptoms - id, symptom Models class Food < ActiveRecord::Base has_many :foodallergies has_many :symptoms, :through => :foodallergies end class Symptom < ActiveRecord::Base has_many :foodallergies has_many :foods,
2006 Jan 31
2
How can I overwrite the parent.children.push(child) Method?
Hi all I want to overwrite the push method (which is an alias of <<, the same as concat) of collections, and there I want to test if :uniq is set to true in the relationship. If so, the method should check if the passed object is already related to the parent, or not (only then it will be added). But I just can''t find the original code of this method, so I could overwrite
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 Feb 11
3
Parameterized ActiveRecord Associations: Any such thing?
Hi list, how are ya? So, my current project is just begging for the ability to have parameterized associations in my ActiveRecord classes. Basically I need something that is a cross between named scopes and standard associations (has_many specifically). I''m wondering if such a thing exists or, if not, if anyone else has an elegant, equivalent solution? Example: class Sprocket <
2007 Jan 23
4
Rails bug reports & patches - why no action?
I have noticed at the dev.rubyonrails.org site that many tickets with pretty clear-cut bug reports/patches or feature enhancements don''t get any attention. They sit there for months at a time. Why is this? Are tickets from those that are not in rails-core deprioritized? Are there just not enough people that have the power to act on tickets? I know it''s not lack of test cases
2007 Jul 17
5
habtm confusion
Hello friends! I am trying to make a database that will have a group of people set to committees, and a person can be in multiple committees, and a committee obviously has multiple people. The people are senators at my university. These are my current models: senator.rb: -- class Senator < ActiveRecord::Base validates_presence_of :first_name, :last_name, :floor has_and_belongs_to_many
2010 Oct 11
8
Nooby Stuck - "has_and_belongs_to_many" relationship
trying to set up a "has_and_belongs_to_many" relationship would very much appreciate the help, not sure what im doing wrong at all. Scheme.rb class Scheme < ActiveRecord::Base validates :schemename, :presence => true belongs_to :user has_many :levels, :dependent => :destroy has_and_belongs_to_many :works end Work.rb class Work < ActiveRecord::Base
2011 Mar 29
0
Issue / code smell in AssociationProxy
I came across an issue in my code and after a hard debug session I found something that smells. First the context of my issue. I have a AR object that has a polymorphic belongs_to currently tied to nothing, I want to dump it to YAML. record.to_yaml This raises the following exception: TypeError: wrong argument type nil (expected Data) from
2008 Nov 06
10
Rails 2.1.2 bug in include on has_many?
In my continued efforts to port my rails 1.x app to Rails 2.1.2, I keep running into what appear to be ActiveRecord bugs. I am using an :include on a :has_many definition: class Request < ActiveRecord::Base has_many :service_types, :order=>''service_types.id ASC'', :include=>:service_response [...] There''s no reason this wouldn''t be supported in
2012 Mar 02
0
ConnectionNotEstablished when using connection on AR::Base abstract subclass
I''m using AR outside of Rails and calling establish_connection on an ActiveRecord::Base abstract_class subclass (to protect my connection in case anyone else is using AR). It was working just fine with AR 3.0.9, but I recently attempted to upgrade to AR 3.2.2. Now, when I hit a "nested" query from a has_many, I get a ActiveRecord::ConnectionNotEstablished. If I call
2007 Aug 03
0
acts_as_paranoid and Association Extensions (has_one troubles)
Hi... Isn''t there a proper way or hack/workaround for the following? * For the example with unfortunate disabilities.. look below,,, Usage of has_* (associationmethods) do {def with_deleted AccociatedModel#with_scope} {Paranoid''s#find_with_deleted}... The has_one associations give me a nil object when invoking it with Model.association_OBJECT.with_deleted. Has_many does like
2006 Mar 13
0
Problems with association named :task
I have an object that belongs_to :task, and calling that object''s task method returns the task it belongs to in the unit tests. One place in a controller, though, it gives me the error: undefined method `find'' for Rake::Task:Class ./script/../config/../vendor/rails/activerecord/lib/active_record/associations/belongs_to_association.rb:44:in `find_target''
2005 Jun 02
0
Don't use an attribute/column that matches a Kernel method (including 'y')
I''ve found a problem, and it might be bug in Ruby itself, but I''m not sure. Say I''ve got a model object (Point) whose table contains column "y". Model Circle has_one Point center. When I load a Center from the database, I"m unable to get the actual value for y. Here is a summary of what I see when I debug into Circle.center.y: Stepping into y(), I
2006 May 20
1
acts_as_paranoid overrides ActiveRecord::Base??
Guys, I am trying to figure out what exactly does this line do at the end of "acts_as_paranoid" plugin? ActiveRecord::Base.send :include, Caboose::Acts::Paranoid::ActiveRecord My problem: I have some classes that I use acts_as_paranoid, and others with tagging support. Classes declared as taggable, throw error, which appears to be in the acts_as_paranoid version of the
2006 Mar 27
2
:through and STI
Hi, I''m trying to use :through and STI using the trunk version of Rails, but I get the following error see bottom of this msg[1] here are my classes. class Player < ActiveRecord::Base end class Ladder < ActiveRecord::Base has_many :subscriptions has_many :players, :through => :subscriptions end class SingleLadder < Ladder end class Subscription <