Class: Raif::ApplicationRecord

Inherits:
Object
  • Object
show all
Includes:
Concerns::BooleanTimestamp
Defined in:
app/models/raif/application_record.rb

Class Method Summary collapse

Class Method Details

.table_name_prefixObject



29
30
31
# File 'app/models/raif/application_record.rb', line 29

def self.table_name_prefix
  "raif_"
end

.where_json_not_blank(column_name) ⇒ ActiveRecord::Relation

Returns a scope that checks if a JSON column is not blank (not null and not empty array)

Parameters:

  • column_name (Symbol, String)

    the name of the JSON column

Returns:

  • (ActiveRecord::Relation)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/raif/application_record.rb', line 14

def self.where_json_not_blank(column_name)
  quoted_column = connection.quote_column_name(column_name.to_s)

  case connection.adapter_name.downcase
  when "postgresql"
    where.not(column_name => nil)
      .where("jsonb_array_length(#{quoted_column}) > 0")
  when "mysql2", "trilogy"
    where.not(column_name => nil)
      .where("JSON_LENGTH(#{quoted_column}) > 0")
  else
    raise "Unsupported database: #{connection.adapter_name}"
  end
end