We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d90ff46 commit 4b39dedCopy full SHA for 4b39ded
1 file changed
lib/jsonapi/resource.rb
@@ -326,6 +326,21 @@ def default_attribute_options
326
{ format: :default }
327
end
328
329
+ def relationship(*attrs)
330
+ options = attrs.last.is_a?(Hash) ? attrs.last : {}
331
+ klass = case options[:to]
332
+ when :one
333
+ Association::HasOne
334
+ when :many
335
+ Association::HasMany
336
+ else
337
+ #:nocov:#
338
+ fail ArgumentError.new('to: must be either :one or :many')
339
340
+ end
341
+ _associate(klass, *attrs)
342
343
+
344
def has_one(*attrs)
345
_associate(Association::HasOne, *attrs)
346
0 commit comments