From 7fdce21be15b35460f692781a6bb4d8468bc4321 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Doyle Date: Thu, 17 Oct 2019 15:48:53 -0400 Subject: [PATCH] Mark resource relation as optional --- lib/generators/rolify/templates/role-active_record.rb | 4 ++-- lib/generators/rolify/templates/role-mongoid.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/generators/rolify/templates/role-active_record.rb b/lib/generators/rolify/templates/role-active_record.rb index 02ee848d..8918b018 100644 --- a/lib/generators/rolify/templates/role-active_record.rb +++ b/lib/generators/rolify/templates/role-active_record.rb @@ -5,7 +5,7 @@ def self.table_name_prefix end <% end %> has_and_belongs_to_many :<%= user_cname.tableize %>, :join_table => :<%= "#{table_name(user_cname, true)}_#{table_name(role_cname, true)}" %> - belongs_to :resource, :polymorphic => true - + belongs_to :resource, :polymorphic => true, :optional => true + scopify end diff --git a/lib/generators/rolify/templates/role-mongoid.rb b/lib/generators/rolify/templates/role-mongoid.rb index 432a3c8b..12c417fb 100644 --- a/lib/generators/rolify/templates/role-mongoid.rb +++ b/lib/generators/rolify/templates/role-mongoid.rb @@ -2,8 +2,8 @@ class <%= role_cname.camelize %> include Mongoid::Document has_and_belongs_to_many :<%= user_cname.tableize %> - belongs_to :resource, :polymorphic => true - + belongs_to :resource, :polymorphic => true, :optional => true + field :name, :type => String index({