Web Manager
2006-Mar-13 17:13 UTC
[Rails] Trouble Using AR Object based on a Piggyback Query?
Hi, I''m new to Rails and Ruby and can''t access methods/columns from an ActiveRecord object that is a "piggy-back" row as described by David here: http://www.loudthinking.com/arc/000235.html Via Console I can create the piggyback object but reading attributes gives "TypeError: cannot convert String into Integer" (this is in Console and the browser). Some commented Console output is below, and any help is very much appreciated! (I can also post my model object if needed.) # This is a regular old ActiveRecord object>> obj => #<ContractHc:0x22f40ec @attributes={"hc_zip"=>nil, "coi_signature"=>"asd", "hc_address_one"=>"16 Wetfoot Road", "hc_organization"=>"GFH Inc.", "coi_signature_date"=>"2006-03-08 13:22:10", "id_people"=>"1", "id_projects"=>"1", "hc_ssn"=>"", "hc_recipient_name"=>"asd", "hc_department"=>"Posse HFR", "hc_ip"=>"127.0.0.1", "id_t_panel_members"=>"1", "id_panel_members"=>"1", "hc_accepts_honoraria"=>"0", "hc_region"=>"Wild West", "id_states"=>"1", "hc_signature_email"=>"jjames@winchester.com", "hc_verification_code"=>"123456", "hc_address_two"=>"Apartment B", "hc_signature_date"=>"2006-03-11 21:25:07", "hc_city"=>"Carson City", "id_panels"=>"1", "id_countries"=>"1", "hc_signature"=>"asd"}># Here I''m accessing it''s data fine...>> obj["hc_city"] => "Carson City"# This is an ActiveRecord object which uses a hand-written piggyback query in the model (the query is working fine as you can see...)>> obj2 => [#<ContractHc:0x22e8e2c @attributes={"city"=>"Carson City", "zip"=>"22122", "region"=>"Wild West", "dep_name_short"=>"Posse HFR", "kind"=>"Active", "pnl_name_long"=>"New Mexico and Texas Posse", "org_name_short"=>"GFH Inc.", "ssn"=>"221-34-6720", "prj_name_long"=>"Wild West Remediation 2006", "id_panel_members"=>"1", "address_two"=>"Apartment B", "address_email"=>"jjames@winchester.com", "id_states"=>"1", "id_countries"=>"1", "address_one"=>"16 Wetfoot Road", "name_first"=>"Jesse", "name_last"=>"James", "text_hon"=>"This is your db-derived hon text."}>]# My error is here: I can''t get data out/access properties for some reason...>> obj2["city"] TypeError: cannot convert String into Integerfrom (irb):65:in `[]'' from (irb):65 (Btw, I''ve used Lasso, ASP3, Php, JSP/Servelets and am _really_ enjoying Rails.) JW -- Posted via http://www.ruby-forum.com/.
Web Manager
2006-Mar-13 18:00 UTC
[Rails] Re: Trouble Using AR Object based on a Piggyback Query?
Hi, A little more looking and I''ve seen that obj (the standard AR record) is an object of the type ContractHc, while obj2 is of type Array. The [] below show this as well, I suppose. So my question now is why am I getting back two differrent types of objects? This doesn''t seem to be the expected behavior described for a piggyback query at all. Thanks, JDW>>> obj => #<ContractHc:0x22f40ec @attributes={"hc_zip"=>nil, "coi_signature"=>"asd", "hc_address_one"=>"16 Wetfoot Road", "hc_organization"=>"GFH Inc.", "coi_signature_date"=>"2006-03-08 13:22:10", "id_people"=>"1", "id_projects"=>"1", "hc_ssn"=>"", "hc_recipient_name"=>"asd", "hc_department"=>"Posse HFR", "hc_ip"=>"127.0.0.1", "id_t_panel_members"=>"1", "id_panel_members"=>"1", "hc_accepts_honoraria"=>"0", "hc_region"=>"Wild West", "id_states"=>"1", "hc_signature_email"=>"jjames@winchester.com", "hc_verification_code"=>"123456", "hc_address_two"=>"Apartment B", "hc_signature_date"=>"2006-03-11 21:25:07", "hc_city"=>"Carson City", "id_panels"=>"1", "id_countries"=>"1", "hc_signature"=>"asd"}>>>> obj2 => [#<ContractHc:0x22e8e2c @attributes={"city"=>"Carson City", "zip"=>"22122", "region"=>"Wild West", "dep_name_short"=>"Posse HFR", "kind"=>"Active", "pnl_name_long"=>"New Mexico and Texas Posse", "org_name_short"=>"GFH Inc.", "ssn"=>"221-34-6720", "prj_name_long"=>"Wild West Remediation 2006", "id_panel_members"=>"1", "address_two"=>"Apartment B", "address_email"=>"jjames@winchester.com", "id_states"=>"1", "id_countries"=>"1", "address_one"=>"16 Wetfoot Road", "name_first"=>"Jesse", "name_last"=>"James", "text_hon"=>"This is your db-derived hon text."}>]-- Posted via http://www.ruby-forum.com/.
Web Manager
2006-Mar-13 18:13 UTC
[Rails] Re: Trouble Using AR Object based on a Piggyback Query?
Ok, just FYI what I''m gettting back is a single AR base object for obj, and an array of AR base objects for obj2. I suppose this is to be expected, and obj2[0]["city"] will of course reference the data. JW -- Posted via http://www.ruby-forum.com/.
Chris Hall
2006-Mar-13 19:04 UTC
[Rails] Re: Trouble Using AR Object based on a Piggyback Query?
it seems you have answered your own question but i just wanted to make one comment. in the future you might want to reconsider posting name/address/ssn information to a public mailing list. i realize the information might be dummy data, and if that is the case, feel free to ignore the comment. just an FYI. On 3/13/06, Web Manager <webmanager@aibs.org> wrote:> > Ok, just FYI what I''m gettting back is a single AR base object for obj, > and an array of AR base objects for obj2. I suppose this is to be > expected, and obj2[0]["city"] will of course reference the data. > > JW > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060313/6db908ad/attachment.html
Web Manager
2006-Mar-13 19:47 UTC
[Rails] Re: Re: Trouble Using AR Object based on a Piggyback Query?
Hi Chris, Thanks for the note, which is a good point! The data is in fact dummy data and as such you can e-mail Jesse James at jjames@winchester.com for proof ;-) Cheers! -- Posted via http://www.ruby-forum.com/.