lib/rom/sql/relation.rb in rom-sql-1.2.2 vs lib/rom/sql/relation.rb in rom-sql-1.3.0

- old
+ new

@@ -76,11 +76,11 @@ # @return [SQL::Relation] # # @api public class_eval <<-RUBY, __FILE__, __LINE__ + 1 def by_pk(#{schema.primary_key.map(&:name).join(', ')}) - where(#{schema.primary_key.map { |attr| "schema[:#{attr.name}] => #{attr.name}" }.join(', ')}) + where(#{schema.primary_key.map { |attr| "self.class.schema[:#{attr.name}] => #{attr.name}" }.join(', ')}) end RUBY else # @!method by_pk(pk) # Return a relation restricted by its primary key @@ -88,17 +88,19 @@ # @param [Object] pk The primary key value # # @return [SQL::Relation] # # @api public - define_method(:by_pk) do |pk| - if primary_key.nil? - raise MissingPrimaryKeyError.new("Missing primary key for "\ - ":#{ schema.name }") - else - where(schema[primary_key] => pk) + class_eval <<-RUBY, __FILE__, __LINE__ + 1 + def by_pk(pk) + if primary_key.nil? + raise MissingPrimaryKeyError.new( + "Missing primary key for :\#{schema.name}" + ) + end + where(self.class.schema[self.class.schema.primary_key_name].qualified => pk) end - end + RUBY end end # @api private def self.associations