[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

:through relationship

Ganesh Kumar

8/12/2008 7:10:00 AM

Hi,
Is it possible to use :through in has_and_belongs _to_many
relationship
--
Posted via http://www.ruby-....

3 Answers

Phlip

8/12/2008 11:40:00 AM

0

Ganesh Kumar wrote:

> Is it possible to use :through in has_and_belongs _to_many
> relationship

I guess it's my turn to apply the rubber stamp!

Ruby is a language. Rails, and ActiveRecord, are frameworks written in that
language. The best forum for questions about them is the Ruby-on-Rails-talk
group at Google Groups.

And there are those (on that newsgroup) who never use habtm because it gets in
the way the instant you think to add a property to the intermediate table. I
suspect :through only works thru has_many - not even belongs_to.

If you only need to access the through item, just write a little accessor for it:

def bars
foos.map(&:bars).flatten
end

--
Phlip

Todd Benson

8/12/2008 4:30:00 PM

0

On Tue, Aug 12, 2008 at 2:09 AM, Ganesh Kumar <gani_chinta@yahoo.com> wrote:
> Hi,
> Is it possible to use :through in has_and_belongs _to_many
> relationship

Why would you want to do this?

Todd

David Masover

8/13/2008 3:42:00 AM

0

On Tuesday 12 August 2008 02:09:36 Ganesh Kumar wrote:
> Hi,
> Is it possible to use :through in has_and_belongs _to_many
> relationship

This isn't a Rails forum, but I'll bite anyway.

I suspect the right way is to simply use "has_many :through" _instead_ of the
habtm relationship. If you're needing to get through to the other side, you
can (probably) do that, too -- at least, I remember this working, the last
time I tried:

has_many :foos
has_many :bars, :through => :foos
has_many :others, :through => :bars

It's been awhile, though, so I'm not sure.