Doubt in retrievind data from habtm?


I have one table called agencies_contract i need to get data from this table

agency_id contract_id 1 1

so i need to display agency_id equivalent to 1 and contract_id equivalent to 1

this table has habtm relation

how do i need to write query for this

any idea

Plz help