Open
Description
The response from the server is missing the embedded target/data/type, or rather replacing it with the empty string...
class Api::V1::ActivityResource < JSONAPI::Resource
has_one :user
has_one :target, polymorphic: true
attributes :previous_value, :new_value, :message, :created_at
attribute :activity_type # this is included for now as JSONAPI::Resources sends model type as "activities"
def activity_type
@model.type
end
end
irb(main):001:0> Activity.first
Activity Load (0.7ms) SELECT "activities".* FROM "activities" ORDER BY "activities"."id" ASC LIMIT 1
=> #<NewRecord id: 1,
user_id: nil,
target_id: 239,
target_type: "Facility", # <= target_type is correct
previous_value: nil,
new_value: nil,
message: nil,
type: "NewRecord",
created_at: "2015-10-13 15:16:12",
updated_at: "2015-10-13 15:16:12">
http://localhost:3000/api/v1/activities/1?include=target,user
:
{
"data": {
"id": "1",
"type": "activities",
"links": {
"self": "http://localhost:3000/api/v1/activities/1"
},
"attributes": {
"previous-value": null,
"new-value": null,
"message": null,
"created-at": "2015-10-13T15:16:12.964Z",
"type": "NewRecord"
},
"relationships": {
"user": {
"links": {
"self": "http://localhost:3000/api/v1/activities/1/relationships/user",
"related": "http://localhost:3000/api/v1/activities/1/user"
},
"data": null
},
"target": {
"links": {
"self": "http://localhost:3000/api/v1/activities/1/relationships/target",
"related": "http://localhost:3000/api/v1/activities/1/target"
},
"data": {
"type": "", // <== should be "Facility"
"id": "239"
}
}
}
}
}