Found this: http://dev.rubyonrails.org/ticket/9797
However, doesn''t seem to solve my issue.
I run this:
Foo.find(:first).to_json(:include => { :bar => { :only =>
[:x,:y] } } )
or
Foo.find(:first).to_json(:include => :bar )
I get:
ArgumentError: wrong number of arguments (0 for 1)
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/serialization.rb:75:in `y''
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/serialization.rb:75:in `send''
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
active_record/serialization.rb:75:in `serializable_record''
........
These all run fine without issue:
Bar.find(:first).to_json
Foo.find(:first).to_json(:include => { :bar => { :only => [:x] } } )
Foo.find(:first).to_json
It''s very similar to the defect that was mentioned in the ticket,
however, the issue comes up when including the model.
Can anyone shed some light? Am I doing something wrong?
Thanks,
Roel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
I''d suggest you actually want:
Foo.find(:first, {:include => {:bar => {:only => [:x, :y]}}).to_json
The :include optional param was in the wrong spot. It belongs inside
the parameter list of ActiveRecord::Base.find
Julian.
Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO
OUT 3rd APRIL
http://sensei.zenunit.com/
On 02/04/2008, at 5:26 PM, Roel wrote:
>
> Found this: http://dev.rubyonrails.org/ticket/9797
>
> However, doesn''t seem to solve my issue.
>
> I run this:
>
> Foo.find(:first).to_json(:include => { :bar => { :only =>
> [:x,:y] } } )
> or
> Foo.find(:first).to_json(:include => :bar )
>
> I get:
>
> ArgumentError: wrong number of arguments (0 for 1)
> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
> active_record/serialization.rb:75:in `y''
> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
> active_record/serialization.rb:75:in `send''
> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
> active_record/serialization.rb:75:in `serializable_record''
> ........
>
> These all run fine without issue:
>
> Bar.find(:first).to_json
> Foo.find(:first).to_json(:include => { :bar => { :only => [:x] } }
)
> Foo.find(:first).to_json
>
> It''s very similar to the defect that was mentioned in the ticket,
> however, the issue comes up when including the model.
>
> Can anyone shed some light? Am I doing something wrong?
>
> Thanks,
>
> Roel
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
@Julian: Actually there is an :include option in both the find and
#to_json methods. With find it instructs ARec to construct a join and
bring back the associated model(s) in one db cycle. Similarly, in
to_json it instructs ARec to include the associations in the rendered
json. You might want to fact-check your ActiveRecord free-for-a-
limited-time video...
@Roel: I just tried the code below in my domain without problems.
Could the difference be that :include must name an association? In my
domain, User has_many :courts, :through=>:court_users
andy = User.find(:first, :include=>:courts)
andy.to_json :except=>[:crypted_password, :salt],
:include=>{:user_cash_adjustment_account=>{:only=>:opening_balance}}
#=>{
"updated_at":"2008/04/01 09:18:44 -0400",
"activated_at":null,
"deleted_at":null,
"remember_token_expires_at":"2008/04/15 13:18:44 -0400",
"activation_code":null,
"id":1,
"courts":[{
"jems_code":"GVL"},{
"jems_code":"SPG"}
],
"default_court_id":2,
"remember_token":"d1956c81b94199ee9ad06b6e82f87e44490ad86f",
"login":"AndyV",
"state":"active",
"email":"...andy...",
"created_at":"2007/09/05 08:33:49 -0400",
"active":true}
On Apr 2, 2:54 am, Julian Leviston
<jul...-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org>
wrote:> I''d suggest you actually want:
>
> Foo.find(:first, {:include => {:bar => {:only => [:x,
:y]}}).to_json
>
> The :include optional param was in the wrong spot. It belongs inside
> the parameter list of ActiveRecord::Base.find
>
> Julian.
>
> Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO
> OUT 3rd APRILhttp://sensei.zenunit.com/
>
> On 02/04/2008, at 5:26 PM, Roel wrote:
>
>
>
> > Found this:http://dev.rubyonrails.org/ticket/9797
>
> > However, doesn''t seem to solve my issue.
>
> > I run this:
>
> > Foo.find(:first).to_json(:include => { :bar => { :only =>
> > [:x,:y] } } )
> > or
> > Foo.find(:first).to_json(:include => :bar )
>
> > I get:
>
> > ArgumentError: wrong number of arguments (0 for 1)
> > from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
> > active_record/serialization.rb:75:in `y''
> > from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
> > active_record/serialization.rb:75:in `send''
> > from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/
> > active_record/serialization.rb:75:in `serializable_record''
> > ........
>
> > These all run fine without issue:
>
> > Bar.find(:first).to_json
> > Foo.find(:first).to_json(:include => { :bar => { :only =>
[:x] } } )
> > Foo.find(:first).to_json
>
> > It''s very similar to the defect that was mentioned in the
ticket,
> > however, the issue comes up when including the model.
>
> > Can anyone shed some light? Am I doing something wrong?
>
> > Thanks,
>
> > Roel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Thanks Julian and Andy for the response. Here are my associations: Foo has_one Bar Bar belongs_to Foo I am able to use to_json method if I only specify to include column x from the bar object. If i include column y, that is when I get error. Is there an issue using column named "y"? From the link I provided above, it states this "Add "Model.define_attribute_methods" to your rails after_initialize callback so the "y" accessor is automatically generated." Where would I add that? To my model? Any help is much appreciated. Roel On Apr 2, 9:53 am, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote:> @Julian: Actually there is an :include option in both the find and > #to_jsonmethods. With find it instructs ARec to construct a join and > bring back the associated model(s) in one db cycle. Similarly, into_jsonit instructs ARec to include the associations in the rendered > json. You might want to fact-check your ActiveRecord free-for-a- > limited-time video... > > @Roel: I just tried the code below in my domain without problems. > Could the difference be that :include must name an association? In my > domain, User has_many :courts, :through=>:court_users > > andy = User.find(:first, :include=>:courts) > andy.to_json:except=>[:crypted_password, :salt], :include=>{:user_cash_adjustment_account=>{:only=>:opening_balance}} > #=>{ > "updated_at":"2008/04/01 09:18:44 -0400", > "activated_at":null, > "deleted_at":null, > "remember_token_expires_at":"2008/04/15 13:18:44 -0400", > "activation_code":null, > "id":1, > "courts":[{ > "jems_code":"GVL"},{ > "jems_code":"SPG"} > ], > "default_court_id":2, > "remember_token":"d1956c81b94199ee9ad06b6e82f87e44490ad86f", > "login":"AndyV", > "state":"active", > "email":"...andy...", > "created_at":"2007/09/05 08:33:49 -0400", > "active":true} > > On Apr 2, 2:54 am, Julian Leviston <jul...-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote: > > > I''d suggest you actually want: > > > Foo.find(:first, {:include => {:bar => {:only => [:x, :y]}}).to_json > > > The :include optional param was in the wrong spot. It belongs inside > > the parameter list of ActiveRecord::Base.find > > > Julian. > > > Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO > > OUT 3rd APRILhttp://sensei.zenunit.com/ > > > On 02/04/2008, at 5:26 PM, Roel wrote: > > > > Found this:http://dev.rubyonrails.org/ticket/9797 > > > > However, doesn''t seem to solve my issue. > > > > I run this: > > > > Foo.find(:first).to_json(:include => { :bar => { :only => > > > [:x,:y] } } ) > > > or > > > Foo.find(:first).to_json(:include => :bar ) > > > > I get: > > > > ArgumentError: wrong number of arguments (0 for 1) > > > from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > > active_record/serialization.rb:75:in `y'' > > > from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > > active_record/serialization.rb:75:in `send'' > > > from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > > active_record/serialization.rb:75:in `serializable_record'' > > > ........ > > > > These all run fine without issue: > > > > Bar.find(:first).to_json > > > Foo.find(:first).to_json(:include => { :bar => { :only => [:x] } } ) > > > Foo.find(:first).to_json > > > > It''s very similar to the defect that was mentioned in the ticket, > > > however, the issue comes up when including the model. > > > > Can anyone shed some light? Am I doing something wrong? > > > > Thanks, > > > > Roel--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Right you are! BTW, It''s actually a general "Rails" set of videos, and it''s pretty basic - nothing about JSON in it :P You''re right, include must name an association, just like in AR::Base#find Have a look at the bottom part of: http://api.rubyonrails.org/classes/ActiveRecord/Serialization.html#M001135 :only is to specify the fields returned. Julian. Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO (#2) OUT NOW! http://sensei.zenunit.com/ On 03/04/2008, at 12:53 AM, AndyV wrote:> > @Julian: Actually there is an :include option in both the find and > #to_json methods. With find it instructs ARec to construct a join and > bring back the associated model(s) in one db cycle. Similarly, in > to_json it instructs ARec to include the associations in the rendered > json. You might want to fact-check your ActiveRecord free-for-a- > limited-time video... > > @Roel: I just tried the code below in my domain without problems. > Could the difference be that :include must name an association? In my > domain, User has_many :courts, :through=>:court_users > > > andy = User.find(:first, :include=>:courts) > andy > .to_json > :except > = > > > [:crypted_password > , :salt > ], :include > =>{:user_cash_adjustment_account=>{:only=>:opening_balance}} > #=>{ > "updated_at":"2008/04/01 09:18:44 -0400", > "activated_at":null, > "deleted_at":null, > "remember_token_expires_at":"2008/04/15 13:18:44 -0400", > "activation_code":null, > "id":1, > "courts":[{ > "jems_code":"GVL"},{ > "jems_code":"SPG"} > ], > "default_court_id":2, > "remember_token":"d1956c81b94199ee9ad06b6e82f87e44490ad86f", > "login":"AndyV", > "state":"active", > "email":"...andy...", > "created_at":"2007/09/05 08:33:49 -0400", > "active":true} > > On Apr 2, 2:54 am, Julian Leviston <jul...-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote: >> I''d suggest you actually want: >> >> Foo.find(:first, {:include => {:bar => {:only => [:x, :y]}}).to_json >> >> The :include optional param was in the wrong spot. It belongs inside >> the parameter list of ActiveRecord::Base.find >> >> Julian. >> >> Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO >> OUT 3rd APRILhttp://sensei.zenunit.com/ >> >> On 02/04/2008, at 5:26 PM, Roel wrote: >> >> >> >>> Found this:http://dev.rubyonrails.org/ticket/9797 >> >>> However, doesn''t seem to solve my issue. >> >>> I run this: >> >>> Foo.find(:first).to_json(:include => { :bar => { :only => >>> [:x,:y] } } ) >>> or >>> Foo.find(:first).to_json(:include => :bar ) >> >>> I get: >> >>> ArgumentError: wrong number of arguments (0 for 1) >>> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ >>> active_record/serialization.rb:75:in `y'' >>> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ >>> active_record/serialization.rb:75:in `send'' >>> from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ >>> active_record/serialization.rb:75:in `serializable_record'' >>> ........ >> >>> These all run fine without issue: >> >>> Bar.find(:first).to_json >>> Foo.find(:first).to_json(:include => { :bar => { :only => [:x] } } ) >>> Foo.find(:first).to_json >> >>> It''s very similar to the defect that was mentioned in the ticket, >>> however, the issue comes up when including the model. >> >>> Can anyone shed some light? Am I doing something wrong? >> >>> Thanks, >> >>> Roel > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sorry, I thought you were just being very generic... not actually asking about a column specifically named ''y''. On Apr 2, 8:43 pm, Roel <rsbon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks Julian and Andy for the response. > > Here are my associations: > Foo has_one Bar > Bar belongs_to Foo > > I am able to use to_json method if I only specify to include column x > from the bar object. If i include column y, that is when I get error. > > Is there an issue using column named "y"? > > From the link I provided above, it states this "Add > "Model.define_attribute_methods" to your rails after_initialize > callback so the "y" accessor is automatically generated." > > Where would I add that? To my model? > > Any help is much appreciated. > > Roel > > On Apr 2, 9:53 am, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote: > > > @Julian: Actually there is an :include option in both the find and > > #to_jsonmethods. With find it instructs ARec to construct a join and > > bring back the associated model(s) in one db cycle. Similarly, into_jsonit instructs ARec to include the associations in the rendered > > json. You might want to fact-check your ActiveRecord free-for-a- > > limited-time video... > > > @Roel: I just tried the code below in my domain without problems. > > Could the difference be that :include must name an association? In my > > domain, User has_many :courts, :through=>:court_users > > > andy = User.find(:first, :include=>:courts) > > andy.to_json:except=>[:crypted_password, :salt], :include=>{:user_cash_adjustment_account=>{:only=>:opening_balance}} > > #=>{ > > "updated_at":"2008/04/01 09:18:44 -0400", > > "activated_at":null, > > "deleted_at":null, > > "remember_token_expires_at":"2008/04/15 13:18:44 -0400", > > "activation_code":null, > > "id":1, > > "courts":[{ > > "jems_code":"GVL"},{ > > "jems_code":"SPG"} > > ], > > "default_court_id":2, > > "remember_token":"d1956c81b94199ee9ad06b6e82f87e44490ad86f", > > "login":"AndyV", > > "state":"active", > > "email":"...andy...", > > "created_at":"2007/09/05 08:33:49 -0400", > > "active":true} > > > On Apr 2, 2:54 am, Julian Leviston <jul...-AfxEtdRqmE/tt0EhB6fy4g@public.gmane.org> wrote: > > > > I''d suggest you actually want: > > > > Foo.find(:first, {:include => {:bar => {:only => [:x, :y]}}).to_json > > > > The :include optional param was in the wrong spot. It belongs inside > > > the parameter list of ActiveRecord::Base.find > > > > Julian. > > > > Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW VIDEO > > > OUT 3rd APRILhttp://sensei.zenunit.com/ > > > > On 02/04/2008, at 5:26 PM, Roel wrote: > > > > > Found this:http://dev.rubyonrails.org/ticket/9797 > > > > > However, doesn''t seem to solve my issue. > > > > > I run this: > > > > > Foo.find(:first).to_json(:include => { :bar => { :only => > > > > [:x,:y] } } ) > > > > or > > > > Foo.find(:first).to_json(:include => :bar ) > > > > > I get: > > > > > ArgumentError: wrong number of arguments (0 for 1) > > > > from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > > > active_record/serialization.rb:75:in `y'' > > > > from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > > > active_record/serialization.rb:75:in `send'' > > > > from /usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ > > > > active_record/serialization.rb:75:in `serializable_record'' > > > > ........ > > > > > These all run fine without issue: > > > > > Bar.find(:first).to_json > > > > Foo.find(:first).to_json(:include => { :bar => { :only => [:x] } } ) > > > > Foo.find(:first).to_json > > > > > It''s very similar to the defect that was mentioned in the ticket, > > > > however, the issue comes up when including the model. > > > > > Can anyone shed some light? Am I doing something wrong? > > > > > Thanks, > > > > > Roel--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---