JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Related resources not backed by an association

Đang mở
#545 4 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Ruby
Star
2.3k
Fork
546
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Hello, I'm curious to see if anyone is interested in allowing a resource to have a relationship that isn't necessarily an association to the underlying model. For example:

A Video has_many :tags. I've created an instance method (Video#related_videos) that pulls related videos based on a video's set of tags.

video.related_videos
=> [related_video_1, related_video_2]

What I'm interested in is having the corresponding VideoResource aware that this isn't an association it should be looking for, but rather public method. This would allow the following requests:

videos/:id?include=related_videos
videos/:id/relationships/related_videos

Currently, an InvalidInclude exception will be raised since "related_videos is not a valid relationship of videos." What if we were to pass a flag to relationship / has_many / has_one? Maybe there's a better way, but I was thinking something like:

VideoResource < JSONAPI::Resource
  has_many :related_videos, instance_method: true
end

Would something like this be worth exploring? I'd be happy to work on a PR to support something like this if there's any interest.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách xem xét các khai báo quan hệ tài nguyên (relationship, has_manyhas_one) cùng đường dẫn InvalidInclude được mô tả trong issue. Xác định cách một phương thức public như Video#related_videos có thể được biểu diễn và cung cấp thông qua hai request ví dụ; tiêu chí hoàn thành yêu cầu thống nhất về API và hành vi validation.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
rails, ruby
Lĩnh vực
api, backend
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.