Method: Dynamoid::Associations::ClassMethods#has_many
- Defined in:
- lib/dynamoid/associations.rb
#has_many(name, options = {}) ⇒ Object
Declare a has_many association for this document.
class Category
include Dynamoid::Document
has_many :posts
end
Association is an enumerable collection and supports following addition operations:
-
create -
create! -
destroy_all -
delete_all -
delete -
<<
-
where -
all -
empty? -
size
When a name of an associated class doesn’t match an association name a class name should be specified explicitly either with class or class_name option:
has_many :labels, class: Tag
has_many :labels, class_name: 'Tag'
When associated class has own belongs_to association to the current class and the name doesn’t match a name of the current class this name can be specified with inverse_of option:
class Post
include Dynamoid::Document
belongs_to :item, class_name: 'Tag'
end
class Tag
include Dynamoid::Document
has_many :posts, inverse_of: :item
end
80 81 82 |
# File 'lib/dynamoid/associations.rb', line 80 def has_many(name, = {}) association(:has_many, name, ) end |