Can I use a jsonb field as a foreign_key in a belongs_to association? Something along the lines of:
belongs_to :product, class_name: "Product", foreign_key: "data ->'product_id'"
References can be defined only between columns (or groups of columns), as it is stated in the documentation:
FOREIGN KEY ( column_name [, ... ] ) REFERENCES reftable [ ( refcolumn [, ... ] ) ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With