Pls see below.
On 7/23/06, Caio Chassot <[EMAIL PROTECTED]> wrote:
If I create a new record with associated records, to me that means that I need a new two new class definitions and some fixtures. Is this correct?
Thanx that's what I was looking for for generating a diff on windows.
For the tests. The actual change is one line. (see below)
> 2. Assuming that it is a reasonable thing to have, how do I go about
> a. writing a test for the patch
You mean that as "where do I put my tests?" or "what do I test for?"
If the former, look around the existing tests, see if it fits within
any, otherwise create a new test file. If the latter, create a record
with associated records and one without them. Try to destroy each.
Test that one raised an error (or returned false, depends on how you
implement it), and that the other was destroyed.
If I create a new record with associated records, to me that means that I need a new two new class definitions and some fixtures. Is this correct?
> b. submitting a patch, (I'm on windows)
Can you redirect output in the windows shell? I think so, not sure.
Anyway, get the svn command line tools, open cmd, go to the rails
working copy where you made the changes, and type:
svn diff > myfile.diff
Thanx that's what I was looking for for generating a diff on windows.
Then attach the generated file to a ticket in trac (which probably is
not working yet, so just post it here)
You should make the change on a subversion working copy of the rails
source, not on an unversioned copy. Also, if you add any new files,
be sure to `svn add` them.
> Do I write a seperate class with the option included? I really
> have no idea, very noob at this.
You mean for the actual change or the tests?
change: You should probably alter the code that handles the dependent
attribute in place.
tests: see above.
For the tests. The actual change is one line. (see below)
If you're not sure about the quality of the final patch, post it here
and we'll go over it.
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core
The actual code to include for the patch is in http://dev.rubyonrails.org/svn/rails/trunk/activerecord/lib/active_record/associations.rb
and is
def configure_dependency_for_has_many(reflection)Basically I'm just halting the destroy option if there are no children. There will need to be a similar line in the has_one method.
if reflection.options [:dependent] && reflection.options[:exclusively_dependent]
raise ArgumentError, ':dependent and :exclusively_dependent are mutually exclusive options. You may specify one or the other.'
end
if reflection.options[:exclusively_dependent]
reflection.options[:dependent] = :delete_all
#warn "The :exclusively_dependent option is deprecated. Please use :dependent => :delete_all instead.")
end
# See HasManyAssociation#delete_records. Dependent associations
# delete children, otherwise foreign key is set to NULL.
# Add polymorphic type if the :as option is present
dependent_conditions = %(#{reflection.primary_key_name} = \#{record.quoted_id})
if reflection.options[:as]
dependent_conditions += " AND #{reflection.options[:as]}_type = '#{base_class.name}'"
end
case reflection.options[:dependent]
when :destroy, true
module_eval "before_destroy '#{reflection.name}.each { |o| o.destroy }'"
when :delete_all
module_eval "before_destroy { |record| #{reflection.class_name}.delete_all(%(#{dependent_conditions})) }"
when : nullify
module_eval "before_destroy { |record| #{reflection.class_name}.update_all(%(#{reflection.primary_key_name} = NULL), %(#{dependent_conditions})) }"
when :restrict
module_eval "before_destroy { |record| #{ reflection.name}.size == 0 }"
when nil, false
# pass
else
raise ArgumentError, 'The :dependent option expects either :destroy, :delete_all, or : nullify'
end
end
def configure_dependency_for_has_one(reflection)
case reflection.options[:dependent]
when :destroy, true
module_eval "before_destroy '#{ reflection.name}.destroy unless #{reflection.name}.nil?'"
when : nullify
module_eval "before_destroy '#{reflection.name}.update_attribute(\"#{reflection.primary_key_name}\", nil)'"
when :restrict
module_eval "before_destroy { |record| #{ reflection.name}.size == 0 }"
when nil, false
# pass
else
raise ArgumentError, "The :dependent option expects either :destroy or : nullify."
end
So then do I just write a couple of classes, matching fixtures and a test file for this?
Thanx for your help
_______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core