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



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

def collection
  Effective::Customer.customers.uniq
    .joins(:user, :subscriptions)
    .select('customers.*, 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, subscriptions.stripe_plan_id, users.email')
end

#search_column(collection, table_column, search_term) ⇒ Object



31
32
33
34
# File 'app/models/effective/datatables/customers.rb', line 31

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