[Rails] Re: Doing Subselect query in Rails... Syntax problem

2008-12-10 Thread Frederick Cheung
On 10 Dec 2008, at 06:55, Priya Dharsini wrote: > > @books = Book.find(:all, :joins=>"books inner join authors as a on > books.title=a.name", :conditions => ['name LIKE ? ', > '%'+params[:author][:name]+'%']) What out for sql injection there. Fred > > > > try with the above code > > Jay Mark w

[Rails] Re: Doing Subselect query in Rails... Syntax problem

2008-12-10 Thread Jay Mark
Jay Mark wrote: > Priya Buvan wrote: >> @books = Book.find(:all, :joins=>"books inner join authors as a on >> books.title=a.name", :conditions => ['name LIKE ? ', >> '%'+params[:author][:name]+'%']) >> >> >> try with the above code > > > > I put the code in Authors Controller as it is, and

[Rails] Re: Doing Subselect query in Rails... Syntax problem

2008-12-10 Thread Jay Mark
Priya Buvan wrote: > @books = Book.find(:all, :joins=>"books inner join authors as a on > books.title=a.name", :conditions => ['name LIKE ? ', > '%'+params[:author][:name]+'%']) > > > try with the above code I put the code in Authors Controller as it is, and I get nil object error. Since I

[Rails] Re: Doing Subselect query in Rails... Syntax problem

2008-12-09 Thread Priya Dharsini
@books = Book.find(:all, :joins=>"books inner join authors as a on books.title=a.name", :conditions => ['name LIKE ? ', '%'+params[:author][:name]+'%']) try with the above code Jay Mark wrote: > I have to use subselect for this query. > find_all_by_name and joins will not work. > Please I nee

[Rails] Re: Doing Subselect query in Rails... Syntax problem

2008-12-09 Thread Priya Dharsini
Hi, Actually what's your requirement? If you tell your requirement clearly then the solution can be found. -- Posted via http://www.ruby-forum.com/. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Ruby on Rails

[Rails] Re: Doing Subselect query in Rails... Syntax problem

2008-12-09 Thread Jay Mark
Jeff Cohen wrote: > On Dec 9, 1:47�pm, Jay Mark <[EMAIL PROTECTED]> wrote: >> Jeff Cohen wrote: >> Thanks for all your help Jeff. >> It is still not working. >> The find_by_name, gives me this error: >> "undefined method `find_by_name' for " > > Can you post the full details of the error mess

[Rails] Re: Doing Subselect query in Rails... Syntax problem

2008-12-09 Thread Jeff
On Dec 9, 1:47 pm, Jay Mark <[EMAIL PROTECTED]> wrote: > Jeff Cohen wrote: > Thanks for all your help Jeff. > It is still not working. > The find_by_name, gives me this error: > "undefined method `find_by_name' for " Can you post the full details of the error message from your log file? Also

[Rails] Re: Doing Subselect query in Rails... Syntax problem

2008-12-09 Thread Jay Mark
Jeff Cohen wrote: > On Dec 9, 11:52�am, Jay Mark <[EMAIL PROTECTED]> wrote: > >> where title is equal to the title returned by the inner query. >> The strange thing here is, title has a unique entry in authors table, >> but title has duplicate entries in the book table. >> >> So, the main point h

[Rails] Re: Doing Subselect query in Rails... Syntax problem

2008-12-09 Thread Jeff
On Dec 9, 11:52 am, Jay Mark <[EMAIL PROTECTED]> wrote: > Here is the table structure: > > Author has id, name, title, book_id  and other columns > Book has id, title, isbn, and other columns. > > They both have the title column. And, yes, authors has book_id as a > foreign key > for books. > The

[Rails] Re: Doing Subselect query in Rails... Syntax problem

2008-12-09 Thread Jay Mark
Jeff Cohen wrote: > On Dec 9, 11:06�am, Jay Mark <[EMAIL PROTECTED]> wrote: >> @books = Books.find_by_sql ["SELECT * FROM books WHERE title IN SELECT >> title FROM authors WHERE name = ?", params[:author][:name]] >> >> One problem is where to put the () that will enclose the inner select. >> Or ma

[Rails] Re: Doing Subselect query in Rails... Syntax problem

2008-12-09 Thread Jeff
On Dec 9, 11:06 am, Jay Mark <[EMAIL PROTECTED]> wrote: > I have to use subselect for this query. > find_all_by_name and joins will not work. > Please I need help with getting the correct syntax for doing subselect > the rails way. > The query works fine in mysql. > I can't find the syntax in the