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

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • 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
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

How would you model the references and citations to publications (articles, books, chapters, etc...)?
I would like to know if you find the following pattern meaningful in domain
I'm new to Rails and don't grasp yet all the possibilities with associations. Here's
I'm writing a structural modeling tool for a civil enginering application. I have one
My program generates relatively simple PDF documents on request, but I'm having trouble with

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.