require File.dirname(__FILE__) + '/joinfix_test_helper' # # hm through # class HasManyThroughWithOptionsMigration < ActiveRecord::Migration def self.up create_table :hm_through_with_options_parents do |t| t.column :field, :string end create_table :hm_through_with_options_children do |t| t.column :field, :string end create_table :hm_through_with_options_joins do |t| t.column :alternate_parent, :integer t.column :alternate_child, :integer end end def self.down drop_table :hm_through_with_options_parents drop_table :hm_through_with_options_children drop_table :hm_through_with_options_joins end end class HmThroughWithOptionsParent < ActiveRecord::Base has_many :through_joins, :class_name => 'HmThroughWithOptionsJoin', :foreign_key => 'alternate_parent' has_many :children, :through => :through_joins, :source => :through_child end class HmThroughWithOptionsChild < ActiveRecord::Base end class HmThroughWithOptionsJoin < ActiveRecord::Base belongs_to :through_child, :class_name => 'HmThroughWithOptionsChild', :foreign_key => 'alternate_child' end class HasManyThroughWithOptionsTest < Test::Unit::TestCase fixtures :hm_through_with_options_parents, :hm_through_with_options_children, :hm_through_with_options_joins def test_has_many_through_with_options setup_fixtures( :hm_through_with_options_parents => %Q{ parent_entry: field: parent value children: - child_one: field: one - child_two: field: two}, :hm_through_with_options_children => "", :hm_through_with_options_joins => "") assert_fixtures( :hm_through_with_options_parents => %Q{ parent_entry: id: 1 field: parent value}, :hm_through_with_options_children => %Q{ child_one: id: 1 field: one child_two: id: 2 field: two}, :hm_through_with_options_joins => %Q{ child_one_parent_entry: id: 1 alternate_parent: 1 alternate_child: 1 child_two_parent_entry: id: 2 alternate_parent: 1 alternate_child: 2}) end end