我想要下面描述的 has_many 关系
class User < ActiveRecord::Base
has_many :mcollections, :foreign_key=>'obj_id'
end
下面是表 mcollections 的定义
create table mcollections (
id int not null auto_increment,
obj_id varchar(255) not null,
category varchar(255) not null,
);
:foreign_key
不是表上的单一字段mcollections
。外键必须是 2 个字段 ( obj_id + category
) 的组合。我怎样才能在User
课堂上指定这个?