search for: associationproxies

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

2008 Feb 22
2
marshaling ActiveRecord objects: how to unload associations?
I''m marshaling ActiveRecord objects, and 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
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 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.
2006 Jul 31
3
Polymorphic associations and single table inheritance
Running into an interesting problem that at first glance appears to be a bug in the AR association code. However, it''s explicitly coded this way so I''m not so sure. I have some code like this: class Address < ActiveRecord::Base belongs_to :addressable, :polymorphic => true end class Person < ActiveRecord::Base has_many :addresses, :as => :addressable,
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 this: obj.msg(containing_model.association_proxy) the exp...
2007 Mar 16
1
Polymorphic find_or_create bug
Today 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.
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