Part of the issue may also be that your model/table names are NOT following convention. The model should be singular, the table name plural underscored lower case:
Model Table Leave leaves Employee employees Assume you also have these in your classes: class Leave < ActiveRecord::Base belongs_to :employee end class Employee < ActiveRecord::Base has_many :leaves belongs_to :manager, :class_name => "Employee" has_many :subordinates, :class_name => "Employee", :foreign_key => "manager_id" end so for Employee (Manager) with id 24: manager = Employee.find(24) leaves = manager.subordinates.collect(&:leaves) (You can also declare a relationship in the Employee model to mimic this if desired in a has_many :through) If you made manager a separate model/table you'd adjust the relationships as appropriate. Niels On Jan 29, 2010, at 9:11 AM, Hemant Bhargava wrote: > Hi Sharagoz, > > This query is not working.. My model names are Leaves and Employee and > table names are leaves and employees. So i tried this query as:- > Leaves.find_by_employee_id (:employee_id, :joins => :employee, > :conditions => [ "employees.manager_id = ?", > session[:employee].manager_id ] ) > > But no results :'( > > Sharagoz -- wrote: >> Something like >> Leave.find_by_employee_id(employee_id, :joins => :employee, :conditions >> => ["employees.manager_id=?", manager_id]) > > -- > 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 rubyonrails-t...@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > -- 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 rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.