Created
April 15, 2014 18:45
-
-
Save jcoglan/10758137 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Migrate from this: | |
class ListItem < ActiveRecord::Base | |
belongs_to :group | |
acts_as_list scope: :group | |
# has id and type columns | |
end | |
class Audio < ListItem | |
end | |
class Video < ListItem | |
end | |
# to this, where parts are temporary measures to support the new models on top of the legacy DB: | |
class ListItem < ActiveRecord::Base | |
belongs_to :content, polymorphic: true, foreign_key: :id, foreign_type: :type | |
belongs_to :group | |
acts_as_list scope: :group | |
def self.inheritance_column | |
:no_such_column_because_type_no_longer_references_subclasses_of_ListItem | |
end | |
end | |
class Audio < ActiveRecord::Base | |
self.table_name = :list_items | |
has_many :list_items, as: :content, foreign_key: :id, foreign_type: :type | |
end | |
class Video < ActiveRecord::Base | |
self.table_name = :list_items | |
has_many :list_items, as: :content, foreign_key: :id, foreign_type: :type | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Am I just being dense here but you seem to be wanting to do a query like this for the
list_items
association:Isn't this only ever going to return itself as a
ListItem
? Is the intention there will be more than one list item in the future? Also there's a problem that:foreign_type
will be suffixed with_type
so it's not going to work against the default:type
column.