:through relationship

Discussion in 'Ruby' started by Ganesh Kumar, Aug 12, 2008.

  1. Ganesh Kumar

    Ganesh Kumar Guest

    Ganesh Kumar, Aug 12, 2008
    #1
    1. Advertising

  2. Ganesh Kumar

    Phlip Guest

    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
    Phlip, Aug 12, 2008
    #2
    1. Advertising

  3. Ganesh Kumar

    Todd Benson Guest

    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
    Todd Benson, Aug 12, 2008
    #3
  4. 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 :eek:thers, :through => :bars

    It's been awhile, though, so I'm not sure.
    David Masover, Aug 13, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan Davenport via .NET 247

    Bind optional one-to-one relationship to textbox

    Dan Davenport via .NET 247, Aug 4, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    632
    Dan Davenport via .NET 247
    Aug 4, 2004
  2. dbuchanan

    DataGridTableStyle and relationship

    dbuchanan, Nov 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    582
    dbuchanan
    Nov 29, 2005
  3. Leon Shaw

    Data Relationship binding

    Leon Shaw, Jul 10, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    563
    Leon Shaw
    Jul 11, 2003
  4. Ken Cox [Microsoft MVP]

    Re: Relationship between IIS Sessions and ASP.NET Sessions?

    Ken Cox [Microsoft MVP], Aug 8, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    5,358
    Luther Miller
    Aug 8, 2003
  5. Frank
    Replies:
    3
    Views:
    353
Loading...

Share This Page