Hello! There is an application on rails, in it, in particular, there is a user table (User model) and a feedback table (Reviews model). The Reviews table has a rating field. One-to-many relationship is configured, i.e. The user may have a lot of feedback. You need to configure the query so that in addition to the required fields from the user table, the field containing the average user rating from the Reviews table is also returned:
@search = User.select("id, name, username").joins(** средний рейтинг **) @search[0].rating # возвращено некоторое значение I note that this field is needed to further render it in json, i.e. callback option
after_find do |user| user.rating = user.reviews.count == 0 ? 0 : user.reviews.sum(:rating)/(user.reviews.count) end attr_accessor :rating does not work. Thank you all in advance!