当前位置: 动力学知识库 > 问答 > 编程问答 >

arrays - Accessing Elements of an ActiveRecord .joins or .includes through a Symbol

问题描述:

This is what I previously do before:

rest_day.employee.actor.name

where "rest_day", "employee" and "actor" are models interconnected through includes and joins. "name" is an attribute of actor.

I would like to access everything through symbols from now on. I get close when I do:

rest_day[employee: :actor]

it outputs the id of actor; but not name. tried several things; not working. How do I get the "name" of the actor?

here is statement:

 @rest_days = RestDay

.includes(employee: [:actor])

.joins(employee: [:actor])

.where("actors.name LIKE ? OR " +

"rest_days.id LIKE ? OR " +

"rest_days.day LIKE ? OR " +

"rest_days.created_at LIKE ? OR " +

"rest_days.updated_at LIKE ? ",

"%#{query[:search_field]}%",

"%#{query[:search_field]}%",

"%#{query[:search_field]}%",

"%#{query[:search_field]}%",

"%#{query[:search_field]}%")

.order(query[:order_parameter] + ' ' + query[:order_orientation])

分享给朋友:
您可能感兴趣的文章:
随机阅读: