Class: Effective::Datatables::Customers

Inherits:
Effective::Datatable
  • Object
show all
Defined in:
app/models/effective/datatables/customers.rb

Instance Method Summary collapse

Instance Method Details

#collectionObject



22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/effective/datatables/customers.rb', line 22

def collection
  Effective::Customer.customers.uniq
    .joins(:user)
    .joins(:subscriptions)
    .select('customers.*')
    .select('users.email AS email')
    .select("array_to_string(array(#{Effective::Subscription.purchased.select('subscriptions.stripe_plan_id').where('subscriptions.customer_id = customers.id').to_sql}), ' ,') AS subscription_types")
    .group('customers.id')
    .group('subscriptions.stripe_plan_id')
    .group('users.email')
end

#search_column(collection, table_column, search_term) ⇒ Object



34
35
36
37
38
39
40
# File 'app/models/effective/datatables/customers.rb', line 34

def search_column(collection, table_column, search_term)
  if table_column[:name] == 'subscription_types'
    collection.where('subscriptions.stripe_plan_id ILIKE ?', "%#{search_term}%")
  else
    super
  end
end