Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 573933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:46:38+00:00 2026-05-13T13:46:38+00:00

I have 4 models: transac, transac_data, item, dvd_details class Transac < ActiveRecord::Base has_many :transac_datas

  • 0

I have 4 models: transac, transac_data, item, dvd_details

class Transac < ActiveRecord::Base
  has_many :transac_datas
  has_many   :items, :through => :transaction_datas
end

class TransactionData < ActiveRecord::Base
  belongs_to :item
  belongs_to :transaction
end

class Item < ActiveRecord::Base
  has_many   :transaction_datas
  has_many   :transacs, :through => :transaction_datas
end

class DvdDetails < ActiveRecord::Base
  has_many :items
end

Now in the “transac” view, I need to access stuff from all these models like:

<td><%=h transac.status %></td>
<% transac.transaction_datas.each do |td| %>
  <td><%=h td.item_type %></td>
<% end %>

<% transac.items.each do |item| %>
  <td><%=h item.item_type %></td>
<% end %>

BUT I also need to access some info from the “DvdDetails” model which is the “furthest” away from transac.

I realized that doing something like this wouldn’t really work:

class Transac < ActiveRecord::Base
  has_many :transac_datas
  has_many :items, :through => :transaction_datas
  has_many :dvd_details, :through => :items, :through => :transaction_datas
end

and do this in the index of “transac” view

<%=h transac.dvd_details.name %>

What do I need to do to accomplish this?

Any help is appreciated!
Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:46:38+00:00Added an answer on May 13, 2026 at 1:46 pm

    Actually, with Ian White’s nested_has_many_through plugin, you can daisy-chain has_many throughs the way you want. Just install the plugin like so:

    script/plugin install git://github.com/ianwhite/nested_has_many_through.git
    

    Then setup your model like this:

    class Transac < ActiveRecord::Base
      has_many :transaction_datas
      has_many :items, :through => :transaction_datas
      has_many :dvd_details, :through => :items
    end
    

    This should do what you need.

    UPDATE: This question has come up a few times recently. I wrote an article, nesting your has_many :through relationships, to explain in detail. It even has an accompanying example application on GitHub to download and play around with.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have models: class Materialtitle < ActiveRecord::Base has_many :edocs end class Edoc < ActiveRecord::Base
I have models: class Model < ActiveRecord::Base has_many :model2 end class Model2 < ActiveRecord::Base
I have models: class User < ActiveRecord::Base has_many :user_skills end class UserSkill < ActiveRecord::Base
Let's say I have models that look like this: class Foo < ActiveRecord::Base has_many
I have models in my app: class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic =>
I have that situation: I have models Item, Region and Country. class Item(models.Model): name
I have three models: class User include Mongoid::Document field :name, :type => String has_many
I have models Category and Deal and having has_many :through mapping via categories_deals .
Right now I have: @models = ActiveRecord::Base.send(:subclasses) But I get this in the log:
I have models like this: class Vendor(models.Model): title = models.CharField() class Product(models.Model): ... vendor

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.