ex_admin icon indicating copy to clipboard operation
ex_admin copied to clipboard

Filter on the foreign key id

Open sreekanthrv opened this issue 8 years ago • 2 comments

Hi,

We have 2 models - user and user_transaction. user_transaction belongs to user. We are able to show the user.id(primary key) in the user_transaction table view. But, we are not able to add the user.id in the filter list. Our use case is to filter all the transactions for a user given his user_id.

Can you please see if we are missing anything. Snippet of our code is:

filter [:id, :user_id, transaction_id, :inserted_at, :updated_at]

index do
    selectable_column
        column :id
        column :transaction_id
        column :user, label: "user_id", fields: [:id]
        column :inserted_at
        column :updated_at
        actions       # display the default actions column
    end
end

We can see other fields in the filter list, but user_id is not showing up.

sreekanthrv avatar Jan 19 '17 13:01 sreekanthrv

Without digging into the code I believe the problem is that label: "user_id" defines a decorator and not an alias you can code against. Trying using the actual column name of "user" and see if that corrects the problem.

frank-taylor-pcg avatar Jan 30 '17 18:01 frank-taylor-pcg

@sreekanthrv has this issue been fixed?

mbramson avatar Mar 24 '17 07:03 mbramson