Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > :through relationship

Reply
Thread Tools

:through relationship

 
 
Ganesh Kumar
Guest
Posts: n/a
 
      08-12-2008
Hi,
Is it possible to use :through in has_and_belongs _to_many
relationship
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Phlip
Guest
Posts: n/a
 
      08-12-2008
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
 
Reply With Quote
 
 
 
 
Todd Benson
Guest
Posts: n/a
 
      08-12-2008
On Tue, Aug 12, 2008 at 2:09 AM, Ganesh Kumar <> wrote:
> Hi,
> Is it possible to use :through in has_and_belongs _to_many
> relationship


Why would you want to do this?

Todd

 
Reply With Quote
 
David Masover
Guest
Posts: n/a
 
      08-13-2008
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 thers, :through => :bars

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server 2000 question: What's the relationship between users and logins Leonard Martin MCSD 0 12-05-2005 09:15 PM
DataGridTableStyle and relationship dbuchanan ASP .Net 1 11-29-2005 06:39 PM
Bind optional one-to-one relationship to textbox Dan Davenport via .NET 247 ASP .Net 0 08-04-2004 01:55 PM
Relationship between Mozilla, Firefox and Thunderbird Lionel B. Dyck Firefox 6 07-19-2004 09:14 AM
Data Relationship binding Leon Shaw ASP .Net 1 07-11-2003 10:14 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57