[英]Namespace rails belongs_to
我有以下配置
module Account
class Permission <ApplicationRecord
end
end
module Account
class GroupPermission < ApplicationRecord
belongs_to: permission
end
end
Table: account_permissions
name character varying,
Table: account_group_permissions
account_permissions_id bigint,
account_groups_id bigint,
當我嘗試訪問Account :: GroupPermission實例並通過它訪問Account :: Permission時返回nil。
僅在我指定class_name時有效:
您的belongs_to
有錯別字嗎? 它應該是belongs_to :permission
此外,在account_group_permissions
表中,將permission_id
用作您的外鍵。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.