Displaying 20 results from an estimated 1200 matches similar to: "marshaling ActiveRecord objects: how to unload associations?"
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,
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",
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 Apr 17
3
using rake db:fixtures:load with rspec fixtures
Hi, I''m new to rspec. I have some fixtures in /spec/fixtures. If they
were in /test/fixtures they could be loaded with rake db:fixtures:load.
Is there any way other than a symlink to load my rspec fixtures into
the database with rake? Or, can I cause rspec to load the fixtures
from /test/fixtures?
Thanks,
Paul
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
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.
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
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 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
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
2008 Jan 04
2
use of Marshal with wxruby classes
Is it possible to use Marshal with wxruby classes to serialize an
application''s state?
I tried a minimal example of simply serializing a minimal frame object, and
I get the error "no marshal_dump is defined for class MinimalFrame".
I don''t fully understand this because I also tried another minimal example
of dumping a class which did not defined a marshal_dump, and it
2007 Apr 21
1
An unknown number of elements
Hi all!
I have a model (Show) than can have an unknown number of dates. And a
date can have an unknown number of shows. Making a Date model seems
icky, espicially since I would have to probably write a lot of glue code
to get the many-many to work easily. I was thinking maybe storing a
Marshaled array of Time objects in a text field, but that isn''t very
clean either... Any Ideas?
--
2007 Aug 17
1
Cookie Sessions in Merb?
I like the cookie sessions that Rails edge has - they make sense,
they''re fast, easy.
For those that don''t know: the default session mechanism is to give
developers a Hash called session. To store this object between
requests it Marshals the session object and sends the object itself
(now as a bitstream) back to clients to store in their cookie file. To
prevent users from
2006 Oct 11
5
Marshal Data too short error with ActiveRecord sess. storage
I''m seeing a "marshal data too short" error with an ActiveRecord store
for my session data.
Other posts say that this happens when the size of the session data
exceeds the size of the "data" column in the sessions table. But my
"data" column is a TEXT field so it seems unlikely that I could have
blown it out.
Has anyone else seen "marshal data too
2004 Sep 25
2
Concerned about Dovecot's new NTLM code
I'm pleased to see another project increasing compatibility with windows
clients, by the addition of NTLM login support, but I'm a bit worried
about a few implementation details, and hope to offer an alternate
approach.
I mean no disrespect to those who have implemented to the code so far,
but I feel that the idea of 'everybody re-implement NTLM' is prone to
failure.
Firstly, to