lib/acts-as-joinable.rb in acts-as-joinable-0.0.1.7 vs lib/acts-as-joinable.rb in acts-as-joinable-0.0.6

- old
+ new

@@ -23,42 +23,59 @@ module ClassMethods def joinable? false end - # the parent in the relationship, so to speak + def acts_as_joinable_on(*args, &block) + args << block if joinable? write_inheritable_attribute(:acts_as_joinable_config, args) else write_inheritable_attribute(:acts_as_joinable_config, args) class_inheritable_reader(:acts_as_joinable_config) class_eval do - has_many :parent_relationships, :class_name => 'ActsAsJoinable::Relationship', :as => :child, :dependent => :destroy - has_many :child_relationships, :class_name => 'ActsAsJoinable::Relationship', :as => :parent, :dependent => :destroy - def self.joinable? true end include ActsAsJoinable::Core end end end - # the child in the relationship, so to speak - def acts_as_joinable(*args, &block) + + def acts_as_joinable + acts_as_joinable_on + end + + def joinable + acts_as_joinable_on + end + + def joins_many(*args, &block) acts_as_joinable_on(*args, &block) end - + + def joins(*args, &block) + acts_as_joinable_on(*args, &block) + end + + def joins_one(*args, &block) + options = args.extract_options! + options[:limit] = 1 + args << options + acts_as_joinable_on(*args, &block) + end + def acts_as_relationship belongs_to :parent, :polymorphic => true belongs_to :child, :polymorphic => true - ActsAsJoinable.models.each do |m| - belongs_to "parent_#{m}".intern, :foreign_key => 'parent_id', :class_name => m.camelize - belongs_to "child_#{m}".intern, :foreign_key => 'child_id', :class_name => m.camelize - end +# ActsAsJoinable.models.each do |m| +# belongs_to "parent_#{m}".intern, :foreign_key => 'parent_id', :class_name => m.camelize +# belongs_to "child_#{m}".intern, :foreign_key => 'child_id', :class_name => m.camelize +# end end end end ActiveRecord::Base.send(:include, ActsAsJoinable) if defined?(ActiveRecord::Base) \ No newline at end of file