Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,7 @@ just as accessible to the Ruby world as MongoDB.
Also, without contributors the project wouldn't be nearly as awesome. So
many thanks to:

* [Josh Menden](https://github.com/joshmenden)
* [Logan Bowers](https://github.com/loganb)
* [Lane LaRue](https://github.com/luxx)
* [Craig Heneveld](https://github.com/cheneveld)
Expand Down
8 changes: 7 additions & 1 deletion lib/dynamoid/associations/belongs_to.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@ def associate(hash_key)
#
# @since 0.2.0
def target_association
has_many_key_name = options[:inverse_of] || source.class.to_s.underscore.pluralize.to_sym
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In every other file the pluralize comes before the underscore, so I changed this to be consistent

has_many_key_name = options[:inverse_of] || source.class.to_s.pluralize.underscore.to_sym
has_one_key_name = options[:inverse_of] || source.class.to_s.underscore.to_sym

if target_class.module_parent != Object && (target_class.module_parent == source.class.module_parent)
has_many_key_name = source.class.to_s.demodulize.pluralize.underscore.to_sym
has_one_key_name = source.class.to_s.demodulize.underscore.to_sym
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we unconditionally demodulize a class name?


unless target_class.associations[has_many_key_name].nil?
return has_many_key_name if target_class.associations[has_many_key_name][:type] == :has_many
end
Expand Down
5 changes: 5 additions & 0 deletions lib/dynamoid/associations/has_and_belongs_to_many.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class HasAndBelongsToMany
# @since 0.2.0
def target_association
key_name = options[:inverse_of] || source.class.to_s.pluralize.underscore.to_sym

if target_class.module_parent != Object && (target_class.module_parent == source.class.module_parent)
key_name = source.class.to_s.demodulize.pluralize.underscore.to_sym
end

guess = target_class.associations[key_name]
return nil if guess.nil? || guess[:type] != :has_and_belongs_to_many

Expand Down
5 changes: 5 additions & 0 deletions lib/dynamoid/associations/has_many.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ class HasMany
# @since 0.2.0
def target_association
key_name = options[:inverse_of] || source.class.to_s.singularize.underscore.to_sym

if target_class.module_parent != Object && (target_class.module_parent == source.class.module_parent)
key_name = source.class.to_s.demodulize.singularize.underscore.to_sym
end

guess = target_class.associations[key_name]
return nil if guess.nil? || guess[:type] != :belongs_to

Expand Down
5 changes: 5 additions & 0 deletions lib/dynamoid/associations/has_one.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class HasOne
# @since 0.2.0
def target_association
key_name = options[:inverse_of] || source.class.to_s.singularize.underscore.to_sym

if target_class.module_parent != Object && (target_class.module_parent == source.class.module_parent)
key_name = source.class.to_s.demodulize.singularize.underscore.to_sym
end

guess = target_class.associations[key_name]
return nil if guess.nil? || guess[:type] != :belongs_to

Expand Down