ActiveRecord中的PostgreSQL jsonb字段属于关联

我可以在belongs_to关联中使用jsonb字段作为foreign_key吗? 有点像:

belongs_to :product, class_name: "Product", foreign_key: "data ->'product_id'" 

只能在列(或列组)之间定义引用,如文档中所述 :

FOREIGN KEY(column_name [,…])REFERENCES reftable [(refcolumn [,…])]

您可以使用activerecord-json-associations来使用PostgreSQL JSONB字段来存储模型的关联信息