search for: associationproxy

Displaying 16 results from an estimated 16 matches for "associationproxy".

Did you mean: association_proxy
2008 Feb 22
2
marshaling ActiveRecord objects: how to unload associations?
...I want them to be as small as possible. How can I unload everything that can be reloaded from the database? If they''re marshaled before any of the associations are referenced then the referenced objects aren''t dumped. But if the association has been loaded, how can I unload it? AssociationProxy.reset doesn''t seem to do it. It seems that after the AssociationProxy has been touched at all then dumping the object causes the AssociationProxy to load everything. Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the...
2011 Mar 29
0
Issue / code smell in AssociationProxy
...; from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/ lib/ruby/1.8/yaml.rb:391:in `quick_emit'' from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/ lib/ruby/1.8/yaml/rubytypes.rb:15:in `to_yaml'' Now to the point: tracing the code path lead me to AssociationProxy#method_missing which for 2.3.x or 3.0.x is very similar: def method_missing(method, *args) if load_target unless @target.respond_to?(method) message = "undefined method `#{method.to_s}'' for \"#{@target}\":#{@target.class.to_s}&quot...
2008 Feb 02
0
Adding methods to Object in Rails -- WARNING
I wanted to do: foo.wrap and wrap would go to a specialized wrap for some types of foo and a general Object#wrap for all the others. So I added wrap to Object class Object def wrap self end end This worked except for objects which are actually AssociationProxy objects pretending to be some other object. The reason is that AssociationProxy removes all but a few methods from itself. You will find this line at the top of vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb instance_methods.each { |m| undef_method m unless m...
2006 Jul 31
3
Polymorphic associations and single table inheritance
...veRecord::Base has_many :addresses, :as => :addressable, :dependent => :destroy end class Member < Person end Adding an Address to a Member results in the addressable_type column equaling "Person" when it should be "Member". Looking in ActiveRecord::Associations::AssociationProxy#set_belongs_to_association_for and ActiveRecord::Associations:: HasManyAssociation#construct_sql it''s clear why. >From ActiveRecord::Associations::AssociationProxy#set_belongs_to_association_for: record["#{@reflection.options[:as]}_type"] = @owner.class.base_class.name.to...
2007 Jul 24
9
will_paginate plugin doesn't work with Association Extensions?
I have: class Post < ActiveRecord::Base has_many :comments do def published find( :all, :conditions => {:published => true} ) end end end When in my controller I do Post.find(:first).comments.published.paginate :page => params[:page] I get an error undefined method `paginate'' for []:Array Is will_paginate supposed to
2006 Feb 04
2
Associations oddity
Can anyone explain this oddity to me? Given two classes as follows: class Question < ActiveRecord::Base belongs_to :category end class Category < ActiveRecord::Base has_many :questions end I get the following: >> q = Question.find 6789 => #<Question:0x37e9e70 @attributes={"id"=>"6789",
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
2007 Aug 22
1
mock framework ethics question
Hi James, Jim, and everyone else who''s listening. I''ve been investigating an interesting bug related to mocks and rails AssociationProxies. See http://rubyforge.org/tracker/?func=detail&atid=3149&aid=12547&group_id=797 for details. The crux is that if you do this (rspec mock syntax): obj.should_receive(:msg).with(mock_of_a_model) and the implementation does
2007 Mar 16
1
Polymorphic find_or_create bug
...oday I just spent 3 hours (and before a demo!) trying to figure out why my polymorphic association fields were breaking. Turns out someone else put in a patch for this 6 months ago. I''m not sure if its the same solution I''d use... I''d rather find_or_create attempt to use AssociationProxy#build if its available and only Base#new if we''re not on a proxy. http://dev.rubyonrails.org/ticket/4645 Can someone on core look at this. I can do another version if anyone would prefer. But, I''d love to have this fixed. Thanks, Hampton. --~--~---------~--~----~------------~-...
2007 Aug 12
3
Scope and specing models
Hello all, I''m currently having an issue with some specs, specifically scope issues (probably more of a scope issue than a spec issue at this point)... Here''s the error: ActiveRecord::AssociationTypeMismatch in ''A new User should know what role it has'' Role expected, got NilClass D:/ruby/projects/restful_authentication_test/config/../app/models/role.rb:5:in
2007 Feb 24
3
Spec failing [Possible Bug with kind_of? and instance_of?]
I have a spec which is failing, but I just can''t say why. Maybe I''m missing something painfully obvious? Here is the pastie of the results & the spec: http://pastie.caboo.se/42626 The spec to look for is "should have an array of users" I''ve printed out ("puts''ed") to the terminal the fact that the values are *opposite* to what
2006 Aug 13
1
Is :finder_sql using #{id} broken?
Hi All, It seems that :finder_sql in a HABTM association only interprets a single quoted #{id} the first time through a query. I see examples of this being used in a few places (though with has_many) and I don''t really see how to use :finder_sql without a #{id}. Am I missing something or is this just broken? -- Paul Haddad (paul.haddad@gmail.com paul@pth.com)
2007 Sep 20
1
Relationship Proxies?
I''m trying to understand these results in irb, which implies that there''s some kind of proxy at play: >> aaron = User.find_by_login ''aaron'' => #<User:0xb7109cdc @attributes={"salt"=>"7e3041ebc2fc05a40c60028e2c4901a81035d3cd", "updated_at"=>nil, "contact_info_id"=>nil,
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
2006 Apr 17
4
Is "target" a reserved word?
I''m working on a cost estimation tool, that allows each estimate created to override base assumptions of price, cost, etc. Everything was fine, until we said, "Let''s add a ''target net revenue'' property." So, the resource model got a "target" column. The override model got a "new_target" column. But, whenever I set
2006 Aug 08
12
delete_if doesn''t work for has_and_belongs_to_many
I''m using Rails-1.1.4 with Ruby-1.8.4 So let''s say I have 2 model classes: class Item has_and_belongs_to_many :things end class Thing has_and_belongs_to_many :items end i = Item.new i.things << Thing.new( :value => "Something").save i.things << Thing.new( :value => "Something Else" ).save i.save Fine, now I have two records in the