Ruby on rails querying with join and condition statement -


i need query joining tables without using primary key(id).

class user < activerecord::base   has_one :participant end  class participant < activerecord::base   belongs_to :user end 

the user has 'id' , 'name'. participant has 'user_id' user.id

i trying find participant.id querying user.name

what have tried is,

participant_id = participant.all :joins => :users, :conditions => {:name => "susie"} 

if you're looking specific user's participant id, go:

user.find_by_name("susie").participant.id 

since user has has_one relation participant(which belongs -- one-to-one) can go call participant on user. activerecord takes care of join magicks


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -