JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Include has_many through: relationship fails

Đang mở
#643 8 bình luận 0 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ả

With the following set of models:

class User < ActiveRecord::Base
    ...
    has_many :participations
    has_many :attempts, through: :participations
    has_many :completed_attempts, -> { completed }, through: :participations, source: :attempts
    ...
end
class Participation < ActiveRecord::Base
    ...
    belongs_to :user
    has_many :attempts
    ...
end
class Attempt < ActiveRecord::Base
    ...
    belongs_to :participation
    ...
end

the request GET /users/1?include=completed-attempts fails. completed-attempts.txt.

Likewise, GET /users/1?include=completed-attempts,attempts fails. completed-attempts_attempts.txt

However, as expected, GET /users/1?include=attempts works. attempts.txt

Changing the order, GET /users/1?include=attempts,completed-attempts, doesn't fail with a 500, however it returns the full list of Attempts for both the attempts and completed-attempts relationships. attempts_completed-attempts.txt

Querying the relations directly from the AR object works correctly for both attempts and completed_attempts.

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 tái hiện các request GET /users/1 được liệt kê với các định nghĩa model User, Participation và Attempt, đồng thời so sánh các response include với các truy vấn ActiveRecord trực tiếp. Điều tra cách xử lý các quan hệ has_many-through đã lọc và thứ tự của các include lồng nhau; được xem là hoàn thành khi completed-attempts chỉ trả về các Attempt đã hoàn thành và tất cả request được liệt kê đều tránh lỗi 500.

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
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/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.