Here is my scenario:
I want to store different types of events in my database. They all share the same fields but will behave differently. Therefore I used Single Table Inheritance.
The table definition for event looks like this:
class AddEvents < ActiveRecord::Migration
def up
create_table :events do |t|
t.date :event_date
t.string :type
t.references :trackable , :polymorphic => true
end
end
def down
drop_table :events
end
end
My event classes look like this (minimum working example):
class Event < ActiveRecord::Base
self.abstract_class = true
belongs_to :trackable, polymorphic: true
[... some validation ]
end
class View < Event; end
class Click < Event; end
class Conversion < Event; end
The table gets created just fine. But when I try to call:
@view1 = FactoryGirl.build(:view1)
With :view1
defined like this:
factory :click1, class: Click do
event_date TEST_CLICK_1_EVENT_DATE
end
I receive the following error message:
Failure/Error: @view1 = FactoryGirl.build(:view1) ActiveRecord::StatementInvalid: Mysql2::Error: Table 'adserve_test.views' doesn't exist: SHOW FULL FIELDS FROM 'views'
I also tried to create a click object from console which gives me the same error. Any ideas how to fix this?