diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-10-28 04:53:22 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-10-28 04:53:22 +0000 |
commit | e7cd7e9d954f90737138495f6418bd4fab428931 (patch) | |
tree | 9c19565b4da5f19048d33f2400c9c4075f68cfd4 /activerecord/lib | |
parent | f2c920ec24f318e28c0a1e78c019a331368ff5bb (diff) | |
download | rails-e7cd7e9d954f90737138495f6418bd4fab428931.tar.gz rails-e7cd7e9d954f90737138495f6418bd4fab428931.tar.bz2 rails-e7cd7e9d954f90737138495f6418bd4fab428931.zip |
r3800@sedna: jeremy | 2005-10-28 00:39:05 -0700
Readonly constraints, association collection method_missing, dup constraint options
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2774 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/association_collection.rb | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 25 |
2 files changed, 17 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index 164d11b2d1..cbfbdf1541 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -128,7 +128,7 @@ module ActiveRecord if @target.respond_to?(method) or (not @association_class.respond_to?(method) and Class.respond_to?(method)) super else - @association_class.constrain(:conditions => @finder_sql, :joins => @join_sql) { @association_class.send(method, *args, &block) } + @association_class.constrain(:conditions => @finder_sql, :joins => @join_sql, :readonly => false) { @association_class.send(method, *args, &block) } end end diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index febb35dd5b..fa7ed9482a 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -384,9 +384,14 @@ module ActiveRecord #:nodoc: def find(*args) options = extract_options_from_args!(args) - # :joins implies :readonly => true if unset. - if options[:joins] and !options.has_key?(:readonly) - options[:readonly] = true + # Inherit :readonly from scope_constraints if set. Otherwise, + # if :joins is not blank then :readonly defaults to true. + unless options.has_key?(:readonly) + if scope_constraints.has_key?(:readonly) + options[:readonly] = scope_constraints[:readonly] + elsif !options[:joins].blank? + options[:readonly] = true + end end case args.first @@ -815,13 +820,15 @@ module ActiveRecord #:nodoc: # Article.constrain(:conditions => "blog_id = 1") do # Article.find(1) # => SELECT * from articles WHERE blog_id = 1 AND id = 1 # end - def constrain(options = {}, &block) - begin - self.scope_constraints = options - block.call if block_given? - ensure - self.scope_constraints = nil + def constrain(options = {}) + options = options.dup + if !options[:joins].blank? and !options.has_key?(:readonly) + options[:readonly] = true end + self.scope_constraints = options + yield if block_given? + ensure + self.scope_constraints = nil end # Overwrite the default class equality method to provide support for association proxies. |