simplelog to mephisto
For some reason, I’ve never ever successfully utilized the converter infrastructure found in vendors/plugins/mephisto_converters/lib/converters
, so I’ve generally had to cobble together my own kludge.
This relies on the following classes:
simplelog/author.rb
module Simplelog
class Author ActiveRecord::Base
establish_connection configurations['simplelog']
has_many :posts, :dependent => :destroy, :class_name => 'Simplelog::Post'
end
end
simplelog/comment.rb
module Simplelog
class Comment ActiveRecord::Base
establish_connection configurations['simplelog']
belongs_to :post, :class_name => 'Simplelog::Post'
end
end
simplelog/page.rb
module Simplelog
class Page ActiveRecord::Base
establish_connection configurations['simplelog']
end
end
simplelog/post.rb
module Simplelog
class Post ActiveRecord::Base
establish_connection configurations['simplelog']
has_and_belongs_to_many :tag,
:class_name => 'Simplelog::Tag',
:join_table => 'tags_posts'
belongs_to :author, :class_name => 'Simplelog::Author'
has_many :comments, :conditions => ['is_approved = ?', true], :dependent => :destroy, :class_name => 'Simplelog::Comment'
end
end
simplelog/tag.rb
module Simplelog
class Tag ActiveRecord::Base
establish_connection configurations['simplelog']
has_and_belongs_to_many :post,
:class_name => 'Simplelog::Post',
:join_table => 'tags_post'
end
end
The Post
definition and the Tag
definition have a little voodoo for dealing with the transition from Rails 1.2 to Rails 2.0. In 1.2, acts_as_taggable
names the join table backwards compared to 2.0, where it uses the normal semantics.
If this weren’t just a hack, I’d probably package it a little more nicely, but as it is, I’d appreciate any tips on how to actually get the converter infrastructure to work.