There is a User model:

has_many :shipments, dependent: :destroy has_many :friendships has_many :friends, through: :friendships has_many :inverse_friendships, :class_name => 'Friendship', :foreign_key => 'friend_id' has_many :inverse_friends, :through => :inverse_friendships, :source => :user 

Friendship model:

 belongs_to :user belongs_to :friend, :class_name => 'User' 

Shipment model:

 belongs_to :user 

How to make it so that a user (User) creating a Shipment object could select one user from the list of friends and attach it to the Shipment model?

For example: User-1 (User) creates a model (Shipment) and attaches to it his friend (Friendship) User-2 (User) - which he selects from the drop-down list of his friends.

  • Is this at all possible or can it somehow be implemented? After all, a User object cannot own another User object through the Shipment model - or something I don’t understand? - lif3ar

1 answer 1

Add the belongs_to :friendship link to the Shipment model, and filter the selection by the creator’s friends. Further work with this connection.

  • I agree, there apparently went too far. Redid the previous commit - still a mistake. - lif3ar