How to write active record query to details by using and <p>i have two tables</p> <p>1)Properties :fields are id, name, propert_type,category_id</p> <p>2)Admins : fields id, name,mobile,category_id</p> <p>i want to write an active record to list all properties , where category_id in properties table and category_id in Admins table are equal, according to current_user_id</p> <p>i am listing this property list by logging as admin.</p> <p>model relation</p> <p><code>class Category &lt; ActiveRecord::Base has_many :admins,dependent: :destroy has_many :properties,dependent: :destroy end</code></p> <p><code>class Admin &lt; ActiveRecord::Base belongs_to :category has_many :properties end</code></p> <p><code>class Property &lt; ActiveRecord::Base belongs_to :admin belongs_to :category end</code></p> <p>i wrote active record like this , but i got error, can anyone please suggest me a solution for this</p> <p><code>@properties= Property.where('properties.category_id=?','admins.category_id=?').and('admins.id=?',current_user.specific.id)</code></p>