I've got a database with an old schema that I'm going to be migrating data from. The table names and relationships are identical to the database. For some reason when I define the models for the old instance, they are acting as though they're the models of the new database.
from_db.rb
class FromDB < ActiveRecord::Base
self.abstract_class = true
establish_connection FROM_DB
end
from_clip.rb
class FromClip < FromDB
self.table_name = "clips"
belongs_to :clippable, polymorphic: true, counter_cache: true
belongs_to :video, class_name: "FromVideo"
end
clip.rb
class Clip < ActiveRecord::Base
belongs_to :clippable, polymorphic: true, counter_cache: true
belongs_to :video
end
console
FromClip.first.class.name
FromClip Load (0.2ms) SELECT `clips`.* FROM `clips` LIMIT 1
=> "Clip"
All the methods and associations available to FromClip are those in the Clip model rather than the FromClip model, but the instance of FromClip is from the correct database. Thanks for your help
Aucun commentaire:
Enregistrer un commentaire