Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #48 from kbrock/non_activerecord_associations

belongs_to_active_hash respects active record's association interface
  • Loading branch information...
commit df745bcddcaa1d335c7d293875701a48af8561dc 2 parents eba92e1 + c17f803
@zilkey authored
View
8 lib/active_hash/base.rb
@@ -39,6 +39,14 @@ class << self
end
end
+ def compute_type(type_name)
+ self
+ end
+
+ def pluralize_table_names
+ true
+ end
+
def data
_data
end
View
7 lib/associations/associations.rb
@@ -16,6 +16,13 @@ def belongs_to_active_hash(association_id, options = {})
define_method("#{association_id}=") do |new_value|
send "#{options[:foreign_key]}=", new_value ? new_value.id : nil
end
+
+ create_reflection(
+ :belongs_to,
+ association_id.to_sym,
+ options,
+ options[:class_name].constantize
+ )
end
end
View
7 spec/associations/associations_spec.rb
@@ -126,6 +126,13 @@ class Book < ActiveRecord::Base
school.city.should be_nil
end
end
+
+ it "finds active record metadata for this association" do
+ School.belongs_to_active_hash :city
+ association = School.reflect_on_association(:city)
+ association.should_not be_nil
+ association.klass.name.should == City.name
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.