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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:28:00+00:00 2026-05-12T07:28:00+00:00

I have a has_many_polymorphs relationship between a Candidate and many events of various type.

  • 0

I have a has_many_polymorphs relationship between a Candidate and many events of various type. In particular, a Candidate creates a Created event when it is created.

class Candidate < ActiveRecord::Base
  has_many_polymorphs :events, :through => :candidate_events,
                               :from => Event::Base.included_in_classes.map { |klass|
                                 klass.to_s.underscore.pluralize.to_sym
                               })
  after_validation_on_create :create_created_event

  private
  def create_creation_event
    Event::Created.create!(:candidate => self, :creator => creator)
  end
end

class CandidateEvent < ActiveRecord::Base
  belongs_to :candidate
  belongs_to :event, :polymorphic => true
end

module Event::Base
  ...
end

class Event::Created < ActiveRecord::Base
  include Event::Base
  validates_presence_of :creator
end

When I run my unit tests, everything is fine. When I run my functional tests, everything is fine. When I run my integration (Cucumber) tests, everything is fine. When I run in production, everything is fine. When I try to run in development mode (with class-reloading on), I get

Referential integrity violation; child <Event::Created:1> was not found for :events.
Expected record['candidate_events.event_id'] (1) to be equal to record['created_events.id'] ().
  {
    "candidate_events.event_type"=>"Event::Created",
    "candidate_events.created_at"=>"2009-08-05 20:28:31",
    "candidate_events.updated_at"=>"2009-08-05 20:28:31",
    "candidate_events.candidate_id"=>"1",
    "candidate_events.event_id"=>"1",
    "candidate_events.id"=>"1"
  }

Running script/console in the same (development) environment I see that Event::Created object with the proper relationship to the CandidateEvent cross-reference model.

What’s going on?

  • 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-12T07:28:01+00:00Added an answer on May 12, 2026 at 7:28 am

    Can we be sure that Event::Base.included_in_classes is returning the right classes when classes reload? Isn’t this trick sort of load order dependent? ie perhaps Event::Created hasn’t yet included Event::Base?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A Person can have many Events and each Event can have one polymorphic Eventable
I have a basic has_many :through relationship that is bi-directional: calendars have many calendar_calendar_events
I have a many to many relationship: Product has many Categories and Category has
I have the following tables: class FinalExam < ActiveRecord::Base belongs_to :course has_many :pages, :as
I have class Question < ActiveRecord::Base has_many :tasks, :as => :task end class QuestionPlayer
I have a Post model: class Post < ActiveRecord::Base attr_accessible :title, :content, :tag_names has_many
I have the following models. # app/models/domain/domain_object.rb class Domain::DomainObject < ActiveRecord::Base has_many :links_from, :class_name
I have class Store < ActiveRecord::Base belongs_to :user has_many :products, :as => :imageable end
I have the following models: class Infoset < ActiveRecord::Base belongs_to :infosetable, :polymorphic => true
I have got two models, User and Event. I need two kind of relationship

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.