I have a setup where I want to be able to build a role record to point to a users skills, venues, productions, groups and so on.
I set it up as a has many through relationship with everything going though roles and roles belonging to everything as so:
class Role < ApplicationRecord
class Group < ApplicationRecord
has_many :users, through: :roles
The default behaviour of Rails 5 belongs_to is that the parent association must be present, so yes, you would need all the fields in order to save a role.
However, to turn off this behaviour, change to:
# config/initializers/new_framework_defaults.rb Rails.application.config.active_record.belongs_to_required_by_default = false # this would disable this configuration for the entire application
Another approach would be to figure out the most important associations and ensure those are available and the set an optional tag on the optional associations, like so:
class Role < ApplicationRecord belongs_to :user belongs_to :skill, optional: true # assume skill & production are optional belongs_to :production, optional: true belongs_to :venue belongs_to :project belongs_to :group end