我试图在SHA1上链接两个表,而不是跨表执行SHA1的查找,并链接via id .
我的模特是
class Dataset < ActiveRecord::Base
belongs_to :dataset_hash
end
class DatasetHash < ActiveRecord::Base
has_many :datasets
end
我尝试使用链接
has_many :datasets, :finder_sql => 'Select datasets.* FROM datasets LEFT JOIN dataset_hashes ON datasets.dataset_hash=dataset_hashes.hash WHERE dataset_hashes.hash=#{dataset.dataset_hash}'
但我只是得到一个错误
数据集哈希(#...)预期,得到字符串(#...)
1 回答
您可以使用belongs_to和has_many中的
:foreign_key
和:primary_key
: