1
votes

I have been trying to figure out the following excerpt from Ruby on Rails official documentation (http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html), and finally gave up. I really don't understand what this is trying to say. I thought I understood everything about associations, until I came across this paragraph. Could someone interpret this? What does it mean by read-only?

An important caveat with going through has_one or has_many associations on the join model is that these associations are read-only. For example, the following would not work following the previous example:

@group.avatars << Avatar.new # this would work if User belonged_to Avatar rather than the other way around

@group.avatars.delete(@group.avatars.last) # so would this

1

1 Answers

0
votes

Because Avatars belong to the group through users, you are unable to add to the collection - it has no User that the Avatar would belong to. The association doesn't make sense to add to, only to read from.