Skip to content

Errors thrown if association uses primary_key other than "id" #30

@lynndylanhurley

Description

@lynndylanhurley

This line is breaking my include associations:

policy.scope.where(id: record_id).exists?

It works if I change from this:

def show?(policy, record_id)
  policy.scope.where(id: record_id).exists?
end

# called on line 75 with:
show?(Pundit.policy!(context[:current_user], record), record.id)

To this:

def show?(policy, record, record_id)
  q = {}
  q[record.class.primary_key] = record_id
  policy.scope.where(q).exists?
end

# call on line 75 with (note the added "record" argument):
show?(Pundit.policy!(context[:current_user], record), record, record.id)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions