[英]Ruby on rails Query related
我有2個模特
文件夾:name:parent_id
AUTHFOLDERS:folder_id:company_id:user_id:角色#用於共享
class Folder < ActiveRecord::Base
has_many :authfolders
has_many :companies, :through => :authfolders
accepts_nested_attributes_for :authfolders
validates :name, presence: true
end
class Authfolder < ActiveRecord::Base
belongs_to :company
belongs_to :folder
end
如何選擇Authfolders.company_id = x
“文件夾”?
您可以加入相關表,然后設置條件:
Folder.joins(:authfolders).where('authfolders.company_id = :company_id', company_id: x)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.