I'm trying to implement a Group system where a User can create a Group and other Users can join the Group.
class User < ApplicationRecord
has_many :groups
end
class Group < ApplicationRecord
belongs_to :owner, :class_name => "User"
has_many :members, :class_name => "User"
end
When checking the owner, I can successfully use:
<% if current_user == @group.owner %>
But I'm unable to check the members of the group with:
<%= @group.members.count %>
As I run into an error:
SQLite3::SQLException: no such column: users.group_id: SELECT COUNT(*) FROM "users" WHERE "users"."group_id" = ?
I think it has something to do with how my Users are setup, but can't figure it out.
Also, once I'm able to have a list containing all the Users that have 'joined' the Group, how do I add/remove Users from that?
Thanks.