Method: Dynamoid::Associations::ClassMethods#has_one
- Defined in:
- lib/dynamoid/associations.rb
#has_one(name, options = {}) ⇒ Object
Declare a has_one association for this document.
class Image
include Dynamoid::Document
has_one :post
end
Association supports following operations:
-
create -
create! -
delete
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_one :item, class: Post
has_one :item, class_name: 'Post'
When associated class has own belong_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 :logo, class_name: 'Image'
end
class Image
include Dynamoid::Document
has_one :post, inverse_of: :logo
end
128 129 130 |
# File 'lib/dynamoid/associations.rb', line 128 def has_one(name, = {}) association(:has_one, name, ) end |