File tree Expand file tree Collapse file tree
test/unit/jsonapi_request Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -437,6 +437,15 @@ def relationship(*attrs)
437437 def has_one ( *attrs )
438438 _add_relationship ( Relationship ::ToOne , *attrs )
439439 end
440+
441+ def belongs_to ( *attrs )
442+ ActiveSupport ::Deprecation . warn "In #{ name } you exposed a `has_one` relationship " \
443+ " using the `belongs_to` class method. We think `has_one`" \
444+ " is more appropriate. If you know what you're doing," \
445+ " and don't want to see this warning again, override the" \
446+ " `belongs_to` class method on your resource."
447+ _add_relationship ( Relationship ::ToOne , *attrs )
448+ end
440449
441450 def has_many ( *attrs )
442451 _add_relationship ( Relationship ::ToMany , *attrs )
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments