class Product < ApplicationRecord
belongs_to :platform
end
class Software < Product
end
class Platform < ApplicationRecord
has_many :products
end
and the following resources:
class ProductResource < JSONAPI::Resource
attributes :name, :description
relationship :platform, to: :one
end
class SoftwareResource < ProductResource
end
class PlatformResource < JSONAPI::Resource
attributes :name
relationship :products, to: :many
end
and this route:
Rails.application.routes.draw do
jsonapi_resources :products
end
Also, I have these records in the database:
platform = Platform.create(name: 'Platform 1')
Software.create(name: 'Software 1', description: 'This is a software', platform: platform)
Doing curl http://localhost:3000/v1/products/1?include=platform -H "Content-Type: application/json" produces the following error:
Internal Server Error: PG::UndefinedColumn: ERROR: column platforms.software_id does not exist.
How do I make JSONAPI::Resources query for products.platform_id instead? It doesn't make sense that it's querying for platforms.software_id when this is a belongs_to association.
I have the following models:
and the following resources:
and this route:
Also, I have these records in the database:
Doing
curl http://localhost:3000/v1/products/1?include=platform -H "Content-Type: application/json"
produces the following error:How do I make JSONAPI::Resources query for
products.platform_id
instead? It doesn't make sense that it's querying forplatforms.software_id
when this is abelongs_to
association.