From 0bafec4b4b13638ecf6488905d03f0bc1d953731 Mon Sep 17 00:00:00 2001 From: rhymes Date: Tue, 3 Sep 2019 21:49:26 +0200 Subject: [PATCH] DOC: Fix aggregated query to avoid deprecation (#3904) [ci skip] --- docs/backend/roles.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/backend/roles.md b/docs/backend/roles.md index ef66256cc..e30f32e00 100644 --- a/docs/backend/roles.md +++ b/docs/backend/roles.md @@ -26,19 +26,20 @@ A new user starts without a any roles and there is no administrative way of addi rails console ``` -1. After verifying the user `test_user_name` is missing the `pro` role we proceed to add and then verify the role has been added. +- after verifying the user `test_user_name` is missing the `pro` role we proceed to add it and then verify the role has been added: ```ruby -User.find_by(username: 'test_user_name').has_role? :pro +> user = User.find_by(username: "test_user_name") +> user.has_role? :pro => false -User.find_by(username: 'test_user_name').add_role :pro +> user.add_role :pro => # -User.find_by(username: 'test_user_name').has_role? :pro +> user.has_role? :pro => true ``` @@ -49,7 +50,7 @@ Another common requirement is changing to the administrative role and an example A more complex query to list all the users and their roles: ```ruby -User.joins(:roles).order(:id).group(:id).pluck(:id, :username,'array_agg(roles.name)') +User.joins(:roles).order(:id).group(:id).pluck(:id, :username, Arel.sql("array_agg(roles.name)")) ``` ## Further Reading