PostgreSQL jsonb field in ActiveRecord belongs to association

Is it possible to use the jsonb field as foreign_key in the belongs_to association? Sort of:

belongs_to :product, class_name: "Product", foreign_key: "data ->'product_id'" 
+6
source share
1 answer

Links can only be defined between columns (or groups of columns), as indicated in the documentation :

FOREIGN KEY (column_name [, ...]) LINKS reftable [(refcolumn) [, ...])]

+2
source

All Articles