0

我有以下关系:

User has_many :relationships
     has_many :friends, :through => :relationships

Friend has_many :relationships

Relationship belongs_to :user, :friend

现在,我想更新friends一个用户,还要更新weight. relationships我应该怎么做?

我试过

Friend
accept_nested_attribute_for :relationships

  friend = my_user.friends.first
   #update info
   friend.update_attributes(:info => my_info, :relationship => {:weight => 1})

在更新其权重属性之前,我应该如何查看用户和朋友之间的特定关系?

4

1 回答 1

2

您需要指定要设置权重的朋友关系,因为正如您的关联所述,有很多。

有不止一种方法可以做到这一点。我可能会这样做:

friend = my_user.friends.first
relationship = my_user.relationships.where(:friend_id => friend.id).first
relationship.update_attributes(:weight => 1)
于 2013-06-18T21:22:31.823 回答