Lucid: How to select column(s) to display in lucid model?

Created on 11 Jan 2018  路  4Comments  路  Source: adonisjs/lucid

This can be done through the query builder using .select, however I am unsure if this is possible using lucid model.
Thanks in advance.

Most helpful comment

Mentioned in the docs http://adonisjs.com/docs/4.0/lucid#_query_builder

The query method on any model returns an instance of query builder and hence you are use any method of the query builder here.

await User.query().select().fetch()

All 4 comments

Have you tried writing the code using a Lucid model?

I did try however there is no method in lucid model (as far as I have seen in the documentation) to show only specific columns in the query similar to a SQL SELECT statement. My options are use query builder or use javascript and loop on the returned object from lucid model method and obtain only the columns I want, although I think the query build approach would be faster. It would be better however if I can do this throught the lucid model.

Mentioned in the docs http://adonisjs.com/docs/4.0/lucid#_query_builder

The query method on any model returns an instance of query builder and hence you are use any method of the query builder here.

await User.query().select().fetch()

Oh, my bad!
Thank you :smile:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

HigoRibeiro picture HigoRibeiro  路  3Comments

hailwood picture hailwood  路  5Comments

ghost picture ghost  路  3Comments

Karnith picture Karnith  路  5Comments

nwashangai picture nwashangai  路  5Comments