0
@@ -3,10 +3,10 @@ module DataMapper
0
- :reload, :offset, :limit, :order, :add_reversed, :fields, :links, :includes, :conditions
0
+ :reload, :offset, :limit, :order, :add_reversed, :fields, :links, :includes, :conditions
, :unique, :group_by0
- attr_reader :repository, :model, *OPTIONS - [ :reload
]
0
+ attr_reader :repository, :model, *OPTIONS - [ :reload
, :unique ]
0
attr_writer :add_reversed
0
alias add_reversed? add_reversed
0
@@ -14,6 +14,10 @@ module DataMapper
0
@@ -42,6 +46,7 @@ module DataMapper
0
# only overwrite the attributes with non-default values
0
@reload = other.reload? unless other.reload? == false
0
+ @unique = other.unique? unless other.unique? == false
0
@offset = other.offset unless other.offset == 0
0
@limit = other.limit unless other.limit == nil
0
@order = other.order unless other.order == model.default_order
0
@@ -67,6 +72,7 @@ module DataMapper
0
# return hash == other.hash
0
@model == other.model &&
0
@reload == other.reload? &&
0
+ @unique == other.unique? &&
0
@offset == other.offset &&
0
@limit == other.limit &&
0
@order == other.order && # order is significant, so do not sort this
0
@@ -136,6 +142,7 @@ module DataMapper
0
"#<#{self.class.name} #{attrs.map { |(k,v)| "@#{k}=#{v.inspect}" } * ' '}>"
0
@@ -157,6 +164,7 @@ module DataMapper
0
@model = model # must be Class that includes DM::Resource
0
@reload = options.fetch :reload, false # must be true or false
0
+ @unique = options.fetch :unique, false # must be true or false
0
@offset = options.fetch :offset, 0 # must be an Integer greater than or equal to 0
0
@limit = options.fetch :limit, nil # must be an Integer greater than or equal to 1
0
@order = options.fetch :order, model.default_order # must be an Array of Symbol, DM::Query::Direction or DM::Property
0
@@ -164,6 +172,7 @@ module DataMapper
0
@fields = options.fetch :fields, @properties.defaults # must be an Array of Symbol, String or DM::Property
0
@links = options.fetch :links, [] # must be an Array of Tuples - Tuple [DM::Query,DM::Assoc::Relationship]
0
@includes = options.fetch :includes, [] # must be an Array of DM::Query::Path
0
+ @group_by = options.fetch :group_by, nil # must be a an Array of Symbol, String or DM::Property
0
@conditions = [] # must be an Array of triplets (or pairs when passing in raw String queries)
0
# normalize order and fields
0
@@ -223,9 +232,11 @@ module DataMapper
0
def assert_valid_options(options)
0
- # validate the reload option
0
- if options.has_key?(:reload) && options[:reload] != true && options[:reload] != false
0
- raise ArgumentError, "+options[:reload]+ must be true or false, but was #{options[:reload].inspect}", caller(2)
0
+ # validate the reload option & unique option
0
+ ([ :reload, :unique ] & options.keys).each do |attribute|
0
+ if options[attribute] != true && options[attribute] != false
0
+ raise ArgumentError, "+options[:#{attribute}]+ must be true or false, but was #{options[attribute].inspect}", caller(2)
0
# validate the offset and limit options
Comments
No one has commented yet.