I want to implement search in my ROR application. I have module
class Employee < ApplicationRecord
belongs_to :parent, class_name: 'Employee'
end
The employee has fields like:
name: string
employee_id: number
The Serializer looks like:
class EmployeeSerializer < ApplicationSerializer
# include FastJsonapi::ObjectSerializer
attributes :name, employee_id, :is_boss, :boss
def boss
object.parent.nil? ? {} : ActiveModel::SerializableResource.new(object.parent)
end
end
A employee will have its own boss. i.e. when is serialize it shows like
{
employee: {
name: "employee_name",
employee_id: 123,
is_boss: false,
boss: {
employee: {
name: "boss name",
employee_id: 1010
}
}
}
}
what happens is when is search from the query Employee.where("employee_id iLike ?", 1212)
its working but i wanted to search based on two thing where it check on employee_id and employes associated boss'es employee_id.
I tried
Employee.where("CONCAT_WS(
' ',
employee_id,
parent.employee_id
)
iLIKE ?",
"%#{params[:query]&.squish}%"
But getting issue on parent.employee_id
Example:
if i query Employee.find(1).parent
it gives the boss information
Thanks
1条答案
按热度按时间omjgkv6w1#
我想您正在寻找: