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

  • Home
  • SEARCH
  • 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
  • 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. 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

Ask A Question

Stats

  • Questions 64k
  • Answers 64k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The reason why this does not work is += when… May 11, 2026 at 10:52 am
  • added an answer If you want to detect if someone is piping data… May 11, 2026 at 10:52 am
  • added an answer With jQuery, you would use the following methods: http://docs.jquery.com/Events/mouseenter#fn http://docs.jquery.com/Events/mouseleave#fn… May 11, 2026 at 10:52 am

Related Questions

I was reading about self-referential has_many :through data situations today, because I'm trying to
I was reading about output buffering in JavaScript here , and was trying to
I was reading about App Engine on wikipedia and came across some GQL restrictions:
I was reading about parsers and parser generators and found this statement in wikipedia's
I was reading about the debuggerstepperboundary attribute and a site says it is is
I was reading about Clojure and found a discussion about Java not supporting tail
I was reading about refactoring a large slow SQL Query over here , and
I was reading about threading and about locking. It is common practise that you
I was reading up about NTVDM.exe as I build a quick test console app
I was recently reading about artificial life and came across the statement, Conway’s Game

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.