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 86271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:13:12+00:00 2026-05-10T22:13:12+00:00

I was reading about self-referential has_many :through data situations today, because I’m trying to

  • 0

I was reading about self-referential has_many :through data situations today, because I’m trying to build a Rails application that uses them. I found this example situation on the Internet, and I have a question about it. Let me post this example code from this guy’s blog:

create_table :animals do |t|   t.string :species end create_table :hunts do |t|   t.integer :predator_id   t.integer :prey_id   t.integer :capture_percent end  class Animal < ActiveRecord::Base   has_many :pursuits,  :foreign_key => 'predator_id',                        :class_name => 'Hunt',                        :dependent => :destroy   has_many :preys,     :through => :pursuits   has_many :escapes,   :foreign_key => 'prey_id',                        :class_name => 'Hunt',                        :dependent => :destroy   has_many :predators, :through => :escapes end class Hunt < ActiveRecord::Base   belongs_to :predator, :class_name => 'Animal'   belongs_to :prey,     :class_name => 'Animal' end 

Let’s say I’m building a web page that lists the first animal in its database. Underneath this heading is a list of percentages (capture_percent). Each percentage is referring to an animal that this page’s animal hunts, but it doesn’t tell you the animal’s name, just the percentage. Clicking on any given percentage will then take you to the corresponding animal’s page.

This is kind of a difficult question to wrap your head around, I know, but I’m trying to figure it out. Would I have to create a separate table for CapturePercent, maybe?

  • 1 1 Answer
  • 3 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. 2026-05-10T22:13:12+00:00Added an answer on May 10, 2026 at 10:13 pm

    Would I have to create a separate table for CapturePercent, maybe?

    Not at all, there doesn’t seem to be anything complicated about this:

    <ul> <% @animal.pursuits.each do |pursuit| %>   <li><%= link_to '#{pursuit.capture_percent}%', pursuit.prey %></li> <% end %> </ul> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just reading through Akka samples, cant't understand how is self.reply defined? As far as
I was reading about output buffering in JavaScript here , and was trying to
I've been reading about self-tracking entities in .net and how they can be generated
I'm reading this article about how to allow a self-signed cert to be used
I was reading about console.log() somewhere on Stackoverflow earlier today, and I remember reading
I'm reading a book about Ruby/Rails and have a question about something simple. In
Reading about the Dispose pattern , I see the documentation repeatedly refer to cleaning
Reading about Kohana templates and saw something I've never seen before: $this->template->title = __('Welcome
Reading about Django, I saw this: http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#ref-contrib-admin - the fancy simple to use admin
Reading about Delphi's Exit statement (see here for instance), I cannot ignore that writing

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.