lapis icon indicating copy to clipboard operation
lapis copied to clipboard

[Feature Request] Add fields option to relations

Open edubart opened this issue 7 years ago • 2 comments

Please add fields option to relations.

For example with has_many:

local Users = Model:extend("users", {
  relations = {
    {"files", has_many = "Files", fields='id, user_id, name' }
  }
})

Use case is when working with large blob columns, like large files in the database, we don't want to always fetch the file data column.

Workaround:

Use relations with fetch option or skip it and use include_in because it has the fields option.

edubart avatar Aug 27 '18 12:08 edubart

@edubart I use include_in and set the fields option. but I get this error:

../luajit/share/lua/5.1/lapis/db/base_model.lua:464: table index is nil

any idea?

linsir avatar Oct 15 '18 07:10 linsir

@linsir Read the docs of include_in at http://leafo.net/lapis/reference/models.html I want to note that for this issue I am currently using relations with fields fetch and preload set and doing manual queries inside them.

edubart avatar Oct 15 '18 16:10 edubart