ruby/sequel/polymorphic.rb
def one_to_many(*args, &block)
          collection_name, options = *args
          options ||= {}

          if able = options[:as]
            able_id           = :"#{able}_id"
            able_type         = :"#{able}_type"
            many_dataset_name = :"#{collection_name}_dataset"

            associate(:one_to_many, collection_name,
              :key        => able_id,
              :reciprocal => able,
              :conditions => {able_type => pluralize(self.to_s.downcase)},
              :adder      => proc { |many_of_instance| many_of_instance.update(able_id => pk, able_type => self.class.to_s) },
              :remover    => proc { |many_of_instance| many_of_instance.update(able_id => nil, able_type => nil) },
              :clearer    => proc { send(many_dataset_name).update(able_id => nil, able_type => nil) }
            )

          else
            associate(:one_to_many, *args, &block)
          end
        end
# Creates a one-to-many relationship. NB: Removing/clearing nullifies the *able fields in the related objects
# Example: Post.one_to_many :comments, as: :commentable
Creates a one-to-many relationship.
Creates a one - to - many relationship .
def one_to_many(*args, &block)
          collection_name, options = *args
          options ||= {}
          if able = options[:as]
            able_id           = :"#{able}_id"
            able_type         = :"#{able}_type"
            many_dataset_name = :"#{collection_name}_dataset"
            associate(:one_to_many, collection_name,
              :key        => able_id,
              :reciprocal => able,
              :conditions => {able_type => pluralize(self.to_s.downcase)},
              :adder      => proc { |many_of_instance| many_of_instance.update(able_id => pk, able_type => self.class.to_s) },
              :remover    => proc { |many_of_instance| many_of_instance.update(able_id => nil, able_type => nil) },
              :clearer    => proc { send(many_dataset_name).update(able_id => nil, able_type => nil) }
            )
          else
            associate(:one_to_many, *args, &block)
          end
        end
def one_to_many ( * args , & block ) collection_name , options = * args options ||= { } if able = options [ :as ] able_id = :" #{ able } _id " able_type = :" #{ able } _type " many_dataset_name = :" #{ collection_name } _dataset " associate ( :one_to_many , collection_name , :key => able_id , :reciprocal => able , :conditions => { able_type => pluralize ( self . to_s . downcase ) } , :adder => proc { | many_of_instance | many_of_instance . update ( able_id => pk , able_type => self . class . to_s ) } , :remover => proc { | many_of_instance | many_of_instance . update ( able_id => nil , able_type => nil ) } , :clearer => proc { send ( many_dataset_name ) . update ( able_id => nil , able_type => nil ) } ) else associate ( :one_to_many , * args , & block ) end end
Creates a one-to-many relationship.
Creates a one - to - many relationship .
args
block