Venkat Eee wrote:
[...]
> Thanks... Rob Biedenharn
>
> I got the solution for that...below code is working fine for me... :-)
You completely missed Rob's point. If you're using Rails, then in most
cases you should be letting ActiveRecord write the SQL, *not writing SQL
yourself*!
>
>
> SELECT * FROM books WHERE customer_id IN (SELECT customer_id FROM
> customers WHERE (IF('#{user_type}' <> 2,customer_id IS NOT
> NULL,company_id='"cus01"')))
This is a waste of time (and the syntax is wrong). What you want is
probably something like
if user_type == 2
books = Customer.find_all_by_company_id('cus01').books
else
books = Customer.find(:all, :conditions => 'company_id is not
null').books
end
See? Much cleaner. If you're going to use Rails, take the time to
learn how to work *with* it, not against it.
Best,
--
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---