Sri
Sri

Reputation: 39

SQL query in Rails 3

How can we write this SQL in Rails3 . tables : node, meta

select n.node_id
from node n
join meta m1 on m1.node_id = n.node_id 
            and m1.code = 'weight' and m1.value = '120'
join meta m2 on m2.node_id = n.node_id
            and m2.code = 'lower' and m2.value = '1'
join meta m3 on m3.node_id = n.node_id
            and m3.code = 'height' and m3.value = ''

Thanks in advance.

Upvotes: 0

Views: 276

Answers (1)

Hck
Hck

Reputation: 9167

You can use ActiveRecord::Base#find_by_sql method to get query results. Read more here.

Upvotes: 1

Related Questions