D
D
dexdev2015-08-17 14:41:26
Ruby on Rails
dexdev, 2015-08-17 14:41:26

What is the correct way to organize prompts for messages in rails?

The company can be the sender of the invitation, or it can be the recipient. The invitation stores information about the sender and the recipient (recipient_id and sender_id). A company may have multiple invitations sent and may have multiple invitations from other companies. Also, the company can accept the invitation or reject it, for this I added confirm:boolean in the Invitation model, now I’m trying to reflect only those companies that accepted the invitation on the form, but I don’t understand how to request only those companies that accepted the invitation? How to pull only those records from the join of the Invitation table that have confirm:true
Invitation

belongs_to :recipient, class_name: 'Company', foreign_key: 'recipient_id'
belongs_to :sender, class_name: 'Company', foreign_key: 'sender_id'

Company
has_many :sent_invitations, class_name: 'Invitation', foreign_key: 'sender_id' — отправленные компанией приглашения
has_many :invitation_recipients, through: :sent_invitations, source: :recipient — получатели приглашений
has_many :incoming_invitations, class_name: 'Invitation', foreign_key: 'recipient_id' — полученные компанией приглашения
has_many :invitation_senders, through: :incoming_invitations, source: :sender — отправители приглашений

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav, 2015-08-17
@crackedmind

Company.joins(: invitation_recipients).where(invitation_recipients: {confirm: true}) like so

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question