Ivan Kuzel

Joined 2/9/2018
# Name
Ivan Kuzel said about 1 year ago:

Thank you very mucho. It was very useful. However, I have a question about how to define columns if we have associations.

For instance, my user object has one country, so if I want to see the country name I would do: user.country.name (country is another table).

How should I define the columns method for that? I tried:
def columns
%w(first_name, country.name)
But it's not correct. Thank you very much in advance.

kobaltz PRO said about 1 year ago:

that definitely adds a level of complexity, but is solvable. the problem comes into play when you start searching. you would need a joins and search on the country as well. you could add a hash into the columns like country: :name and modify the search.

marklar PRO said 11 months ago:

Would you be able to share some sample code for your solution to this?