I have a post model
class Post < ApplicationRecord
belongs_to :account
end
The migration looks like:
class CreatePosts < ActiveRecord::Migration[7.0]
def change
create_table :posts do |t|
t.integer :account_id, null: false
t.string :title, null: false
t.string :content, null: false
t.timestamps
end
end
end
Now when I display a list of these posts, I only display them based on the permission of the user.
class Level< ApplicationRecord
end
class CreateLevels < ActiveRecord::Migration[7.0]
def change
create_table :levels do |t|
t.integer :account_id, null: false
t.string :name, null: false
t.timestamps
end
end
end
So say I have user permissions modelled as Levels:
Level 1
Level 2
Level 3
So each time a Post is created, it will be assigned to 1 more of these levels.
When a user who has level 2 views the list of posts, the user will see ONLY posts that are associated with Level 2.
I guess the table would look like:
- post_id
- level_id
- timestamps
So a Post could belong to 1 more more levels, but I don't think the same post_id will ever be associated to the same level_id in the system.
What type of association would best describe this in Rails/ActiveRecord?
If someone could help tweak my migration and add the appropriate associations to the model.