Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 3 compatibility #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/object_daddy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,12 @@ def generate_missing(args)
(presence_validated_attributes.keys - args.keys).each {|a| req[a.to_s] = true } # find attributes required by validates_presence_of not already set

belongs_to_associations = reflect_on_all_associations(:belongs_to).to_a
missing = belongs_to_associations.select { |a| req[a.name.to_s] or req[a.primary_key_name.to_s] }
if create_scope = scope(:create)
missing.reject! { |a| create_scope.include?(a.primary_key_name) }
end
missing.reject! { |a| [a.name, a.primary_key_name].any? { |n| args.stringify_keys.include?(n.to_s) } }
missing = belongs_to_associations.select { |a| req[a.name.to_s] or req[a.foreign_key.to_s] }

scoped_attributes = scope_attributes.keys
missing.reject! { |a| scoped_attributes.include?(a.foreign_key) }

missing.reject! { |a| [a.name, a.foreign_key].any? { |n| args.stringify_keys.include?(n.to_s) } }
missing.each {|a| args[a.name] = a.class_name.constantize.generate }
end
end
Expand Down