Skip to content

Create record with association using prefix ids #82

Answered by excid3
lostmarinero asked this question in Q&A
Discussion options

You must be logged in to vote

Correct, you'd have to intercept that and decode it to the primary key ID.

Your model can do that with something like this:

def company_id=(value)
  value.start_with?(_prefix_id.prefix) ? super(_prefix_id.decode(value)) : super

  # Or with fallbacks enabled, should be able to just decode without the conditional:
  # super _prefix_id.decode(value, fallback: true).first
end

The more we override of ActiveRecord internals, the more issues arise so we've been trying to keep it minimal.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lostmarinero
Comment options

Answer selected by lostmarinero
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #81 on November 06, 2024 15:46.