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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:34:25+00:00 2026-05-11T08:34:25+00:00

How would you model the references and citations to publications (articles, books, chapters, etc…)?

  • 0

How would you model the references and citations to publications (articles, books, chapters, etc…)?

A publication can be an article, book or a chapter and it has many references to other publications and other publications refer to it (call these citations)

I need to be able to list the relationships among the publications: The references in a publication and the citations from other publications to this publication

My initial understanding is that this would be a polymorphic relationship to handle the different types of publications and that it would require a bidirectionalself join.

My stab at it

Publication belongs_to :writing, :polymorphic =>true has_and_belongs_to_many :references     :class_name => 'Publication'    :join_table => 'reference_citation'     :foreign_key => 'reference_id'    :foreign_key => 'citation_id'  Book,    Chapter,    Article all have: has_many :publications :as =>writing 

I find this a bit confusing so any suggestions that would help clarify it would be great. Even object and field naming suggestions.

[I asked a less clear version of this question here.]

I also probably need to use has many through because I will need the ability to destroy the relationship

  • 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-11T08:34:26+00:00Added an answer on May 11, 2026 at 8:34 am

    Here’s a solution using a self-referential relationship using single table inheritance. Use these commands to create the app:

    $ rails myproject $ cd myproject $ script/generate model publication type:string name:string $ script/generate model citation publication_id:integer reference_id:integer 

    The setup the relationships this way:

    class Publication < ActiveRecord::Base   has_many :citations   has_many :cited_publications, :through => :citations, :source => :reference   has_many :references, :foreign_key => 'reference_id', :class_name => 'Citation'   has_many :refered_publications, :through => :references, :source => :publication end  class Citation < ActiveRecord::Base   belongs_to :publication   belongs_to :reference, :class_name => 'Publication' end  class Article < Publication end  class Book < Publication end  class Chapter < Publication end 

    Now we can create the DB and try it out from the console:

    $ rake db:migrate $ script/console  Loading development environment (Rails 2.2.2) >> a = Article.create!(:name => 'Article') => #<Article id: 1, ...> >> b = Book.create!(:name => 'Book') => #<Book id: 2, ...> >> a.citations.create(:reference => b) => #<Citation id: 1, publication_id: 1, reference_id: 2, created_at: '2009-02-15 14:13:15', updated_at: '2009-02-15 14:13:15'> >> a.citations => [#<Citation id: 1, ...>] >> a.references => [] >> b.citations => [] >> b.references => [#<Citation id: 1, publication_id: 1, reference_id: 2, created_at: '2009-02-15 14:13:15', updated_at: '2009-02-15 14:13:15'>]     >> a.cited_publications => [#<Book id: 2, type: 'Book', name: 'Book', created_at: '2009-02-15 14:11:00', updated_at: '2009-02-15 14:11:00'>] >> a.refered_publications => [] >> b.cited_publications => [] >> b.refered_publications => [#<Article id: 1, type: 'Article', name: 'Article', created_at: '2009-02-15 14:10:51', updated_at: '2009-02-15 14:10:51'>] 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create model binding functionality so a user can enter ','
How would I model a system that needs to be able to provide content
In my model I would like to create a scope that takes advantage of
I have this array property in my model and would like to see it
I am using a standard lm model and would like to set the coefficients
Our company is currently using a simple trunk/release/hotfixes branching model and would like advice
My model is an IEnumerable which I would like to bind to a telerik
I would like to keep model binding when doing ajax calls from my view.
How would I create a Mongoid model that has the ability to be saved
I would like to destroy a nested model if its attributes are blanked out

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.