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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:31:27+00:00 2026-05-24T08:31:27+00:00

Take for example this situation. You have 3 models: Poet – Represents the author

  • 0

Take for example this situation.

You have 3 models:

  1. Poet – Represents the author of a poem
  2. Poem – Represents a poem written by a Poet
  3. Printing – Represents a printed publication of any sort containing the Poet’s Poem.

Right off the bat poet and poem are obvious:

  • Poet has_many poems
  • Poem belongs_to poet

It becomes confusing for me when dealing with the Printing model.

In this case a Printing, in some sense, belongs to both the poet and poem. You could say a poet has_many printings or a poem has_many printings which makes sense but going the inverse route is tricky…

What about a situation where some magazine or book printed 5 poems from one poet? OR, one of the poems is published in 10 different magazines?

It almost seems as if the Printing itself “belongs to many” poems or poets. I know this is wrong, but i’m just trying to articulate the point.

So the answerable question is this:
How would you set up these relationships? Specifically, what would the model and database table look like AND how would you use them to access associated data?

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-24T08:31:27+00:00Added an answer on May 24, 2026 at 8:31 am

    What about a situation where some magazine or book printed 5 poems from one poet?

    Remeber if you have a poet that has many poems and printing that has many poems as well you can alway get the poet.

    Poet.poems.first.printings would return all the printings of the poets first poem

    or you could do Printing.poems.first.poet This way you could get the poet of the first poem in the printing.

    How would you set up these relationships? Specifically, what would the model and database table look like AND how would you use them to access associated data?

    I would set it up like this

    Poet :has_many poems
    poem :belongs_to poet
    poem :has_and_belongs_to_many printings
    printing :has_many poems
    

    Because you are using a has_and_belogs_to_many association you need a join table, for poems and printings

    you would have migration that looks like this

    CreatePoemsPrintingJoinTable < ActiveRecord::Migration
      def self.up
        create_table :poems_printings, :id => false do |t|
          t.integer :poem_id
          t.integer :printing_id
        end
      end
    
      def self.down
        drop_table :poems_printings
      end
    end
    

    The other tables are pretty easy

    CreateTablePoems < ActiveRecord::Migration
      def self.up
        create_table :poems, do |t|
        t.integer :poet_id
        end
      end
    
      def self.down
        drop_table :poems
      end
    end
    
    CreateTablePoets < ActiveRecord::Migration
      def self.up
        create_table :poets do |t|
        end
      end
    
      def self.down
        drop_table :poems
      end
    end
    
    CreateTablePrintings < ActiveRecord::Migration
      def self.up
        create_table :printings do |t|
        end
      end
    
      def self.down
        drop_table :printings
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take this example code (ignore it being horribly inefficient for the moment) let listToString
The questions says everything, take this example code: <ul id=css-id> <li> <something:CustomControl ID=SomeThingElse runat=server
take a look at this example code: public class Comment { private Comment() {
Take a look at this example: http://www.extjs.com/deploy/dev/examples/multiselect/multiselect-demo.html On it, there are components rendered against
Please take a look at this example: #include <iostream> #include <vector> #include <string> using
I need some help adding conditions to a linq query. Take this small example
Take the following example plugin: (function($) { $.fn.alertOnClick = function(text) { return this.each(function(){ $(this).click(alert(text));
I'll attempt to illustrate this with an example. Take a common example of a
Take this code snippet for example: window.location.href = 'mysite.htm#images'; Already being on the site
Take this class as example: public class Category : PersistentObject<int> { public virtual string

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.