0

I was faced with the problem of composing associations.

It turns out that

I have a user, user can have many photo booths.

also photo booths can have many users.

This problem is solved, but I have Group photo booths.

Group photo booths can have many users and many photo books. So

GroupPhotoBooth has many User and PhotoBooth

PhotoBooth has many User and one GroupPhotoBooth

User has many PhotoBooths and GroupPhotoBooths

class User < ApplicationRecord
  has_many :group_photo_booths
  has_many :photo_booths
end

class GroupPhotoBooth < ApplicationRecord
  has_many :photo_booth
  has_many :photo_booths
end

class PhotoBooth < AplicationRecord
  belongs_to :group_photo_booths
  has_many :users
end

But this order confuses me very much. What do i do?

Artem G
  • 41
  • 4

1 Answers1

0

If you're trying to make associations between classes and each class is related to User.

Then you should only make 1 class as User and User has many 'N' associations.

isn't this enough?

class User < ApplicationRecord
  has_many :group_photo_booths
  has_many :photo_booths
end
Isaac
  • 160
  • 1
  • 1
  • 8