How to search joined column?
Closed this issue · 5 comments
tsulatsitamim commented
How to search joined column?
Obapelumi commented
Hi @tsulatsitamim could you please provide a detailed description of what you are trying to do?
tsulatsitamim commented
I've query
const services = await Service
.query()
.join('categories', 'categories.id', 'services.category_id')
.select('services.*', 'categories.name as category_name')
I want to include category_name in search
Obapelumi commented
You can create a Category
model for the categories table, add it as an association on the Service
model and then add categories.name
as a searchable column on the Service
model. For example:
import { search } from 'adosearch'
class Category extends BaseModel {
@column()
name: string
}
class Service extends BaseModel {
@hasMany(() => Category)
categories: HasMany<typeof Category>
static search = search(this, ['categories.name'])
}
Hope this helps
tsulatsitamim commented
I'v datatable on front end, which will sort the column key, if I use categories.name as column key, the sort will not work.
Obapelumi commented
Not sure what you setup looks like but I think this is out of the scope of this package so I'll be closing this issue.