laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org
2008-Feb-15 18:00 UTC
Wrong number of arguments to find_by_sql?
Hi,
I''m trying to run a query that returns columns from different tables
and that joins a couple of tables. Here it is
@result = EcOrder.find_by_sql["select
u1.ship_to_first_name, u1.ship_to_last_name, u1.ship_to_street,
u1.ship_to_state, u1.ship_to_zip, u1.ship_to_city, u1.ship_to_country,
u1.phone, u1.work_phone, u1.work_phone_extension, u1.email, u2.email,
u2.fax, u1.fax from ec_orders o, users u1, users u2 where o.user_id u1.id and
u1.user_id = u2.id and o.id = ?", ec_order_id]
I didn''t know what model to use, since I''m joining a couple.
Anyway
the above produces the error:
ArgumentError in OrderController#submit
wrong number of arguments (0 for 1)
Any clarifications are appreciated, - Dave
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
You need to put parentheses around your argument. @result = EcOrder.find_by_sql(["select u1.ship_to_first_name, u1.ship_to_last_name, u1.ship_to_street, u1.ship_to_state, u1.ship_to_zip, u1.ship_to_city, u1.ship_to_country, u1.phone, u1.work_phone, u1.work_phone_extension, u1.email, u2.email, u2.fax, u1.fax from ec_orders o, users u1, users u2 where o.user_id = u1.id and u1.user_id = u2.id and o.id = ?", ec_order_id]) ...should do. On Feb 15, 11:00 am, "laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org" <laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org> wrote:> Hi, > > I''m trying to run a query that returns columns from different tables > and that joins a couple of tables. Here it is > > @result = EcOrder.find_by_sql["select > u1.ship_to_first_name, u1.ship_to_last_name, u1.ship_to_street, > u1.ship_to_state, u1.ship_to_zip, u1.ship_to_city, u1.ship_to_country, > u1.phone, u1.work_phone, u1.work_phone_extension, u1.email, u2.email, > u2.fax, u1.fax from ec_orders o, users u1, users u2 where o.user_id > u1.id and u1.user_id = u2.id and o.id = ?", ec_order_id] > > I didn''t know what model to use, since I''m joining a couple. Anyway > the above produces the error: > > ArgumentError in OrderController#submit > wrong number of arguments (0 for 1) > > Any clarifications are appreciated, - Dave--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org
2008-Feb-16 21:16 UTC
Re: Wrong number of arguments to find_by_sql?
Thanks, Matt. I have a follow-up question. When I try and access a
column from the result set
@result = EcOrder.find_by_sql(["select
u1.ship_to_first_name, u1.ship_to_last_name, u1.ship_to_street,
u1.ship_to_state, u1.ship_to_zip, u1.ship_to_city, u1.ship_to_country,
u1.phone, u1.work_phone, u1.work_phone_extension, u1.email, u2.email,
u2.fax from ec_orders o, users u1, users u2 where o.user_id = u1.id
and u1.user_id = u2.id and o.id = ?", ec_order_id])
@fax = @result.fax
I get the error
NoMethodError in OrderController#submit
undefined method `fax'' for []:Array
How do I get the column "fax" out of my result set? - Dave
On Feb 15, 12:42 pm, Matt White
<whit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> You need to put parentheses around your argument.
>
> @result = EcOrder.find_by_sql(["select u1.ship_to_first_name,
> u1.ship_to_last_name, u1.ship_to_street, u1.ship_to_state,
> u1.ship_to_zip, u1.ship_to_city, u1.ship_to_country, u1.phone,
> u1.work_phone, u1.work_phone_extension, u1.email, u2.email, u2.fax,
> u1.fax from ec_orders o, users u1, users u2 where o.user_id = u1.id
> and u1.user_id = u2.id and o.id = ?", ec_order_id])
>
> ...should do.
>
> On Feb 15, 11:00 am,
"laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org"
>
>
>
> <laredotorn...-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org> wrote:
> > Hi,
>
> > I''m trying to run a query that returns columns from different
tables
> > and that joins a couple of tables. Here it is
>
> > @result = EcOrder.find_by_sql["select
> > u1.ship_to_first_name, u1.ship_to_last_name, u1.ship_to_street,
> > u1.ship_to_state, u1.ship_to_zip, u1.ship_to_city, u1.ship_to_country,
> > u1.phone, u1.work_phone, u1.work_phone_extension, u1.email, u2.email,
> > u2.fax, u1.fax from ec_orders o, users u1, users u2 where o.user_id
> > u1.id and u1.user_id = u2.id and o.id = ?", ec_order_id]
>
> > I didn''t know what model to use, since I''m joining a
couple. Anyway
> > the above produces the error:
>
> > ArgumentError in OrderController#submit
> > wrong number of arguments (0 for 1)
>
> > Any clarifications are appreciated, - Dave- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On Feb 16, 2008, at 3:16 PM, laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org wrote:> > Thanks, Matt. I have a follow-up question. When I try and access a > column from the result set > > @result = EcOrder.find_by_sql(["select > u1.ship_to_first_name, u1.ship_to_last_name, u1.ship_to_street, > u1.ship_to_state, u1.ship_to_zip, u1.ship_to_city, u1.ship_to_country, > u1.phone, u1.work_phone, u1.work_phone_extension, u1.email, u2.email, > u2.fax from ec_orders o, users u1, users u2 where o.user_id = u1.id > and u1.user_id = u2.id and o.id = ?", ec_order_id]) > @fax = @result.fax > > I get the error > > NoMethodError in OrderController#submit > undefined method `fax'' for []:Array > > How do I get the column "fax" out of my result set? - Dave >@result is an array. You can either do @result.first.fax or iterate over the whole thing with @result.each do |r| do something with r.fax end Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---