JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

`undefined method 'id' for nil:NilClass` when include null none primary key association

Open
#842 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.3k
Forks
546
PR merge metrics
No merged PRs in 30d

Description

create_join_table :members, :articles, {id: false} do |t|
  t.integer :article_id
  t.string :polymorphicable_type
  t.integer :polymorphicable_id
end

class MemberArticles < ApplicationRecord
   belongs_to :article
   belongs_to :polymophicable, polymorphic: true
end
class ArticleRecourse < JSONAPI::Resource
  has_many :members, always_include_linkable_data: true
end

I want serialize articles polymorphic data througth join_table associated

when i use always_include_linkable_data: true or direct serialize members model also throw this exception.

should each resource model entity at least have _primary_key or id method? it is jsonapi-resources convention? If true, Maybe write in documents

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied Rails join-table and polymorphic-association example, starting at serialization of members with always_include_linkable_data enabled. Trace why the associated resource reaches the missing id method, then determine whether resources without a primary key are supported. Done means the behavior is corrected or the supported requirement is clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.