jbox-web / ajax-datatables-rails

A wrapper around DataTable's ajax methods that allow synchronization with server-side pagination in a Rails app
MIT License
585 stars 228 forks source link

Search on association attribute not working. #283

Closed JulienItard closed 6 years ago

JulienItard commented 6 years ago

Hello,

I'm on RoR 4.2, jquery-datatables-rails 3.4.0, ajax-datatable 0.4.0

I have a ScheduledNotification model with a belongs_to Notification and Notification have a name.

The datatable display correctly the name, but the search isn't apply on it. Any idea what's wrong ? Thanks !

  def view_columns
    @view_columns ||= {
      name: { source: "Notification.name" }
    }
  end

  def data
    records.map do |scheduled_notification|
      {
        name: scheduled_notification.notification.name
      }
    end
  end

  private

  def get_raw_records
    ScheduledNotification.includes(:notification)
  end
JulienItard commented 6 years ago

Ok I've found myself. .references(:notification) was missing