Prashant Tiwari
2006-Jul-31 08:52 UTC
[Rails] How to get result of following SQL Query in Ruby?
Hi, I have 2 tables as follows:- _________________ ________________ ____________ taggings | |stores | | tags | -----------------| |---------------| |------------| --tag_id | |--store_id | |tag_id | --store_id | |--store_name | |tag_name | --user_id | |---------------| |------------| -----------------| Now I want to execute followin sql query on above tables:- "select name from tags where tag_id in (select tag_id from taggings where store_id in (select store_id from stores where citylist like ''%1%'')) ;" I am able to get proper result using this sql query. But how should i write same in query ruby inside my controller/model of tags table? i.e Tag.find(:all, :conditions=>...... What will be conditions in above ruby statement? Please tell me ? Thanx in advance. Prash -- Posted via http://www.ruby-forum.com/.
Prashant Tiwari
2006-Jul-31 09:46 UTC
[Rails] Re: How to get result of following SQL Query in Ruby?
Anyways, I solved it by direct writing SQL statement into one of my models... Now its working fine... :) Pras Prashant Tiwari wrote:> Hi, > > I have 2 tables as follows:- > _________________ ________________ ____________ > taggings | |stores | | tags | > -----------------| |---------------| |------------| > --tag_id | |--store_id | |tag_id | > --store_id | |--store_name | |tag_name | > --user_id | |---------------| |------------| > -----------------| > > Now I want to execute followin sql query on above tables:- > "select name from tags where tag_id in (select tag_id from taggings > where store_id in (select store_id from stores where citylist like > ''%1%'')) ;" > > I am able to get proper result using this sql query. But how should i > write same in query ruby inside my controller/model of tags table? > i.e Tag.find(:all, :conditions=>...... > > What will be conditions in above ruby statement? > > Please tell me ? > Thanx in advance. > Prash-- Posted via http://www.ruby-forum.com/.