app/models/user.rb
def groups_with_notebooks
    counts = Notebook.readable_by(self).where(owner: groups).group(:owner_id).count
    groups
      .map {|group| [group, counts.fetch(group.id, 0)]}
      .reject {|_group, count| count.zero?}
  end
# Returns an array of Groups that the user is a member of, and the number of notebooks in that group
Returns an array of Groups that the user is a member of, and the number of notebooks in that group
Returns an array of Groups that the user is a member of and the number of notebooks in that group
def groups_with_notebooks
    counts = Notebook.readable_by(self).where(owner: groups).group(:owner_id).count
    groups
      .map {|group| [group, counts.fetch(group.id, 0)]}
      .reject {|_group, count| count.zero?}
  end
def groups_with_notebooks counts = Notebook . readable_by ( self ) . where ( owner : groups ) . group ( :owner_id ) . count groups . map { | group | [ group , counts . fetch ( group . id , 0 ) ] } . reject { | _group , count | count . zero? } end
Returns an array of Groups that the user is a member of, and the number of notebooks in that group
Returns an array of Groups that the user is a member of and the number of notebooks in that group