All threads / What is the best way to have User in some group and select those groups on Event
Ask A Question

Notifications

You’re not receiving notifications from this thread.

What is the best way to have User in some group and select those groups on Event

Jaroslav Horák asked in Rails

Hi,
I have two models User and Event.
User should belong to one group and User could attend Event based on selected group.
Event could be open for one or many groups.

My first solution was to create a Group model with has_one User and has_and_belongs_to_many for Event.
But client would not change those groups.
So is there a better way to do it without extra model and DB?

I think about something with enums but don't know how to do it with multiple groups on Event.
Or maybe there is some other solution?
Any tips? =)

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 62,791+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.