好的,所以我在 Rails 中有这种关系:
class Position < ActiveRecord::Base
belongs_to :company
belongs_to :user
end
class User < ActiveRecord::Base
has_many :companies, :through => :positions
has_many :positions
class Company < ActiveRecord::Base
has_many :positions
has_many :users, :through => :positions
这是职位的架构:
create_table "positions", :force => true do |t|
t.integer "company_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "regular_user", :default => true
end
这regular_user
是向管理员和员工发出信号,所以我的问题是如何设置regular_user
这些0
数据false
:
@user = User.find(params[:user_id])
@company = Company.find(params[:company_id])
@user.companies << @company
有一个更好的方法吗?我刚在想:
Position.create(user_id: params[:user_id], company_id: params[:company_id], regular_user: 0)
但是有建立协会的标准吗?