Skip to content

Instantly share code, notes, and snippets.

@Bill Bill/seed-fu.rb.diff
Created Oct 31, 2008

Embed
What would you like to do?
===================================================================
--- vendor/plugins/seed-fu/lib/seed-fu.rb (revision 3419)
+++ vendor/plugins/seed-fu/lib/seed-fu.rb (working copy)
@@ -20,7 +20,7 @@
raise "You must set at least one constraint." if constraints.empty?
@constraints = []
constraints.each do |constraint|
- raise "Your constraint `#{constraint}` is not a column in #{@model_class}. Valid columns are `#{@model_class.column_names.join("`, `")}`." unless @model_class.column_names.include?(constraint.to_s)
+ raise "Your constraint `#{constraint}` is not a column in #{@model_class}. Valid columns are `#{@model_class.column_names.join("`, `")}`." unless @model_class.column_names.include?(constraint.to_s) || association = @model_class.reflect_on_association(constraint)
@constraints << constraint.to_sym
end
end
@@ -61,8 +61,18 @@
end
def condition_hash
- @data.reject{|a,v| !@constraints.include?(a)}
+ @data.reject{|a,v| !@constraints.include?(a)}.inject({}) { | memo,( k,v ) | memo[ column_name_for( k ) ] = v.to_param ; memo}
end
+
+ def column_name_for( attribute_or_one_to_one_association_name)
+ if @model_class.column_names.include?(attribute_or_one_to_one_association_name.to_s)
+ attribute_or_one_to_one_association_name
+ elsif association = @model_class.reflect_on_association( attribute_or_one_to_one_association_name)
+ association.association_foreign_key
+ else
+ nil
+ end
+ end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.