Open fredriproad opened 13 years ago
The problem seems to be that your inheritance_column_name
column should be named type
. I know the User Guide uses inheritance_column_name
, but it works for me when using type
.
Second problem is that you shouldn't be specifying t.timestamps
in the level_beta_things
table, these field are already present in the level_alpha_things
table, so you do have ambiguous fields.
Is there a way to ignore the timestamps for now? As they are from existing tables and I want to keep it in case I want to rollback.
I was really psyched about this gem and I've been trying hard to get it to work, with no luck. :-\ I followed the documentation on the site (http://peterhamilton.github.com/citier/user_guide.html), and I couldn't get even the simplest example to run. I'm running SUSE Linux, MySQL 14.14, mysql2 gem, Rails 3.0.9, and Ruby 1.9.
First, there were problems with the migrations. The issue was in create_citier_view -- duplicate/ambiguous field names. (It was taking the timestamp fields from the "root" table and the "child" table.) I had it ignore those fields, and managed to get it to build the tables.
Then, I tried running it, and I get this error: "ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'type' in 'field list'"
In my example, a "LevelAlphaThing" has a name, and a "LevelBetaThing" inherits from LevelAlphaThing and adds a color.
Here's the code:
_the migrations_
class CreateLevelAlphaThings < ActiveRecord::Migration def self.up create_table :level_alpha_things do |t| t.string :name t.string :inheritance_column_name t.timestamps end end
def self.down drop_table :level_alpha_things end end
class CreateLevelBetaThings < ActiveRecord::Migration def self.up create_table :level_beta_things do |t| t.string :color t.timestamps end create_citier_view(LevelBetaThing) end
def self.down drop_table :level_beta_things drop_citier_view(LevelBetaThing) end end
_the models_
class LevelAlphaThing < ActiveRecord::Base
:name, :inheritance_column_name
acts_as_citier end
class LevelBetaThing < LevelAlphaThing
:color
acts_as_citier end
_the test_
require 'test_helper'
class LevelBetaThingTest < ActiveSupport::TestCase def test_should_be_valid x = LevelBetaThing.new x.name = "Fire" x.color = "red" assert x.save end end
_quick patch to core_ext.rb so it doesn't cause ambiguities / doesn't try to create duplicate fields_
def create_citier_view(theclass) ... parent_columns = theclass.superclass.column_names.select{ |c| c != "id" && c != "created_at" && c != "updated_at" } ... end
I really hope I'm doing something wrong; I'd love to get this working!
Thanks!