how to get id of other table

Hi All,
          I have a doubt regarding join tables
I'm having 2 models

and both models have " has and belong to many" relationships
so there are 3 tables

then i'm fetching the data in controller as
@cfacs=Fac.all(:joins=>:conts, :select=>"")

but i dont know how to get the cont_id in the join table from @cfacs

                          for nd in @cfacs
                               puts nd.cont_id

show me an error as "no method in Fac"

Please help me regarding this

Right. You told Rails only to select It's not clear from your post why you are using a :joins in a habtm association, as that should be implied, however something like this should work:

@conts = Cont.all # assumes relatively recent Rails. If older, use Cont.find(:all)
@conts.facs.each do |fac|
   puts fac[:id]

thankyou S.Ross

the problem is I have to get associated with each fac (foreign key)and in the @cfacs=Fac.all(:joins=>:conts, :select=>“”) i’ll rewrite it as
@cfacs=Fac.all(:joins=>:conts, :select=>“facs.,facs_conts.,conts.*”)

Don't do @cfacs=Fac.all
(:joins=>:conts, :select=>"facs.*,facs_conts.*,conts.*")

If you need only the along with any other data that you need,

@cfacs = Fac.all(:include => :conts, :select=> ", facs.*")

You don't need to specify the join as the relationship takes care of

thankyou Mukund
i got it
and it works