0
votes

I have an application with rich client (react+redux) and rails 5 backend API.

In first approximation, we have 3 models

issue.rb

has_many :issue_participants, dependent: :destroy

has_many :participants, through: :issue_participants, class_name: 'User'

issue_participant.rb

belongs_to :issue

belongs_to :participant, class_name: 'User', foreign_key: 'user_id'

and user.rb

has_many :issue_participants, dependent: :destroy

has_many :issues, through: :issue_participants

I want to add participants to issue at frontend side. This will be happen in react component, where redux-form with user's collection will be render (only users, nothing else of current issue).

I choose from two options:

  1. Update an issue with selected users via IssuesController#update action by passing issues_participant_ids: [] to params. Please note that we have no this action right now, because it wasn't needed before today.

  2. Create IssueParticipant records via IssueParticipantsController#create action.

Both options works. Which one should be given preference in the context of predictable consequences?

1

1 Answers

0
votes

I solved the problem in favor of option number 1, because separate creation of related entities issue_participants generates problem with subsequent issue updates.

We should make additional request to know which users already related to issue, instead of take them from issue object if we work in context of issue form.

But if we generally update issue_participants as an issue attributes, we use default rails params behavior and remain within RoR framework convention.