Skip to content

Commit b274613

Browse files
author
Olle Jonsson
committed
Add belongs_to as DSL alias to has_one
1 parent df16278 commit b274613

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

lib/jsonapi/resource.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ def relationship(*attrs)
429429
def has_one(*attrs)
430430
_add_relationship(Relationship::ToOne, *attrs)
431431
end
432+
alias_method :belongs_to, :has_one
432433

433434
def has_many(*attrs)
434435
_add_relationship(Relationship::ToMany, *attrs)

test/unit/jsonapi_request/jsonapi_request_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class CatResource < JSONAPI::Resource
44
attribute :name
55
attribute :breed
66

7-
has_one :mother, class_name: 'Cat'
7+
belongs_to :mother, class_name: 'Cat'
88
has_one :father, class_name: 'Cat'
99

1010
filters :name

0 commit comments

Comments
 (0)