You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am using the groupify gem. And encountered some errors when I would like to use named_groups.
I have tried the following solution. I am using rails 5.1
ActiveRecord::RecordInvalid: Validation failed: Group must exist
class GroupifyMigration < ActiveRecord::Migration[5.1]
def change
create_table :groups do |t|
t.string :name
end
create_table :group_memberships do |t|
t.references :member, polymorphic: true, index: true, null: false
t.references :group, polymorphic: true, index: true
# The named group to which a member belongs (if using)
t.string :group_name, index: true
# The membership type the member belongs with
t.string :membership_type
t.timestamps
end
end
end
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
has_one :membership
has_many :forms
groupify :named_group_member
groupify :group
after_save :create_default_membership
def create_default_membership
user = self.build_membership
#user.membership_name = 'Member'
user.admin = 1
user.save
end
end
The text was updated successfully, but these errors were encountered:
denniswoot
changed the title
ActiveRecord::RecordInvalid: Validation failed: Group must exist from (irb):15 2.3.0 :016 >
ActiveRecord::RecordInvalid: Validation failed: Group must exist
Dec 13, 2018
@pietjepuk111 I think this is because of the new ActiveRecord settings with Rails >5
you can fix this by adding self.belongs_to_required_by_default = false to your GroupMembership model.
Hi, I am using the groupify gem. And encountered some errors when I would like to use named_groups.
I have tried the following solution. I am using rails 5.1
#57
a = User.find 1
=> #<User id: 1, email: "[email protected]", created_at: "2018-12-13 10:25:57", updated_at: "201
8-12-13 10:25:57">
a.groups
ActiveRecord::RecordInvalid: Validation failed: Group must exist
The text was updated successfully, but these errors were encountered: