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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:13:03+00:00 2026-06-10T21:13:03+00:00

A Video , a Song and an Article can have many Tags . And

  • 0

A Video, a Song and an Article can have many Tags. And each Tag also can have many Video, Songs or Articles. So I have 5 models: Video, Song, Article, Tag and Taggings.

Here are these models:

class Video < ActiveRecord::Base
  has_many :tags, :through => :taggings
end

class Song < ActiveRecord::Base
  has_many :tags, :through => :taggings
end

class Article < ActiveRecord::Base
  has_many :tags, :through => :taggings
end

class Tag < ActiveRecord::Base
  has_many :articles
  has_many :videos
  has_many :songs
  belong_to :taggings, :polymorphic => true #is this correct?
end

The database definition of Taggings

create_table "taggings", :force => true do |t|
  t.integer  "tag_id"
  t.string   "taggable_type"
  t.integer  "taggable_id"
  t.datetime "created_at",    :null => false
  t.datetime "updated_at",    :null => false
end

Taggings model:

class Taggings < ActiveRecord::Base
  belongs_to :tag                           #is this correct?
  belong_to :taggable, :polymorphic => true #is this correct?
end

The issue I’m worried by is, do I have right definitions of model (belongs_to, has_many?) ? My gut tells me that I missed something. I’ve seen many articles and I’m quite confused by them.

  • 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-06-10T21:13:05+00:00Added an answer on June 10, 2026 at 9:13 pm

    You need these changes:

    class Video < ActiveRecord::Base # or Song, or Article
      has_many :taggings, :as => :taggable  # add this      
      has_many :tags, :through => :taggings # ok
    
    
    class Tag < ActiveRecord::Base
      # WRONG! Tag has no tagging_id
      # belong_to :taggings, :polymorphic => true
    
      has_many :taggings # make it this way
    
      # WRONG! Articles are available through taggings
      # has_many :articles
    
      # make it this way
      with_options :through => :taggings, :source => :taggable do |tag|
        tag.has_many :articles, :source_type => 'Article'
        # same for videos
        # and for songs
      end
    

    About with_options.

    Your class Taggings seems ok except its name. It has to be singular, Tagging:

    class Tagging < ActiveRecord::Base # no 's'!
      belongs_to :tag                           
      belong_to :taggable, :polymorphic => true 
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here video link for the Arc puzzle Can anyone please tell me what concept
Core video experts, I'm creating a custom video player for .mov files. I have
I have imported video FLV Player(with no skin) in layer(flv1) The flv Player instance
i have a single video (duration: 3 seconds) and i need to create 2
Video tags like below plays fine with iPhone, but not Android: <video id=video width=320
in video tag src we are trying to give src as a ftp resource
Here is the site I am working on: http://t3kno.dewpixel.net/ As you can see there
I have a video of framewidth 1280 and frame height 768. If i set
My Table Structure is: artist_id category 1 Song 1 Song 1 Song 1 Video
how to play a video in iPhone sdk using MPMoviePlayerViewController,here i capture video through

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.