Here is the @q, which is getting the first name, but I want to concat first name and last name as a full name for sorting
@q = company.properties.joins(:owner).select("(first_name || ' ' || last_name) as
full_name").joins("left join units on units.property_id = properties.id").includes(:units,:owner, :contracts, :tags)
.where(total_units_limit).ransack(params[:q])
Here is the SQL query
SELECT CONCAT(first_name, ' ', last_name ) as full_name, *
FROM owners
I want to merge this in query, Does anybody has an idea how can I do this ? I'm new to this thing
@q = company.properties.joins(:owner).select(:id,
"CONCAT(first_name,' ',last_name) as name").joins("left join
units on units.property_id = properties.id ").includes(:units,
:owner, :contracts, :tags)
.where(total_units_limit).ransack(params[:q])
but I'm getting this error if I'm trying like this
PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY
expressions must appear in select list
LINE 1: ... $16, $17, $18, $19, $20, $21, $22, $23) ORDER BY
"propertie...
SELECT COUNT(*) FROM (SELECT DISTINCT "properties"."id",
CONCAT(first_name,' ',last_name) as name FROM "properties"
INNER JOIN "owners" ON "owners"."id" =
"properties"."owner_id" LEFT OUTER JOIN "units"
"units_properties" ON "units_properties"."property_id" =
"properties"."id" AND "units_properties"."deleted_at" IS NULL
LEFT OUTER JOIN "contracts" ON "contracts"."property_id" =
"properties"."id" AND "contracts"."deleted_at" IS NULL LEFT
OUTER JOIN "taggings" ON "taggings"."taggable_id" =
"properties"."id" AND "taggings"."taggable_type" = $1 AND
"taggings"."context" = $2 LEFT OUTER JOIN "tags" ON "tags"."id"
= "taggings"."tag_id" left join units on units.property_id =
properties.id WHERE "properties"."deleted_at" IS NULL AND
"properties"."company_id" = $3 AND "properties"."id" IN ($4,
$5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17,
$18, $19, $20, $21, $22, $23) ORDER BY "properties"."name"
ASC) subquery_for_count