Class: List
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- List
- Includes:
- Boards::Listable, Importable
- Defined in:
- app/models/list.rb
Constant Summary
Constants inherited from ApplicationRecord
Constants included from ResetOnUnionError
ResetOnUnionError::MAX_RESET_PERIOD
Instance Attribute Summary
Attributes included from Importable
Instance Method Summary collapse
Methods included from Boards::Listable
#collapsed?, #destroyable?, #movable?, #title, #update_preferences_for
Methods inherited from ApplicationRecord
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
Methods included from SensitiveSerializableHash
Instance Method Details
#as_json(options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/list.rb', line 33 def as_json( = {}) super().tap do |json| json[:collapsed] = false if .key?(:collapsed) json[:collapsed] = collapsed?([:current_user]) end if .key?(:label) json[:label] = label.as_json( project: board.project, only: [:id, :title, :description, :color], methods: [:text_color] ) end end end |
#preferences_for(user) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/list.rb', line 20 def preferences_for(user) return preferences.build unless user BatchLoader.for(list_id: id, user_id: user.id).batch(default_value: preferences.build(user: user)) do |items, loader| list_ids = items.map { |i| i[:list_id] } user_ids = items.map { |i| i[:user_id] } ListUserPreference.where(list_id: list_ids.uniq, user_id: user_ids.uniq).find_each do |preference| loader.call({ list_id: preference.list_id, user_id: preference.user_id }, preference) end end end |