Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A administrate
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 96
    • Issues 96
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 32
    • Merge requests 32
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • thoughtbot, inc.
  • administrate
  • Merge requests
  • !2292

Use correct key in unconventional associations

  • Review changes

  • Download
  • Email patches
  • Plain diff
Open Pablo Brasero requested to merge github/fork/pablobm/associated-primary-key into main Nov 29, 2022
  • Overview 0
  • Commits 4
  • Pipelines 1
  • Changes 6

A fix for a bug that you can reproduce right now easily: visit the demo app (https://administrate-prototype.herokuapp.com/admin/customers), select any customer, edit, save, and the customer will lose their territory value.

This is a bug introduced with https://github.com/thoughtbot/administrate/pull/1633, where I failed to use associated_primary_key to refer to the key on the other side of a foreign key.

Specifically in our demo app, the Customer model belongs to Country . However instead of the conventional matching of Customer#country_id to Country#id, it should match Customer#country_code to Country#code. While foreign_key gives us country_code, we wrongly use primary_key for the counterpart. Instead we should use association_primary_key which gives us code.

Fixes https://github.com/thoughtbot/administrate/issues/2169

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/pablobm/associated-primary-key