Open mcvmcv opened 2 years ago
Some context from discord: 7/ It looks like there is confusion around whether you can specify a field in a subtype of AbstractModel that doesn't have a corresponding database column. I have found that SearchLight complains if I try to add one. Are there updates or something that I'm missing?
Essenciary: Normally it shouldn't - it just uses the fields that map column names. Can you open an issue with a MWE?
Franku: The thing you miss is the possibility to work with fields which are not stored in the database. I call them virtual fields in the environment of working with databases. They are not virtual because you can work with them inside your program but they will not be stored in the database. This could be reached by a technic I had implemented in the past which is gone with the PR. A specific function was defined to translate fields of the model into fields which are stored to the database. This works for two things. 1. You can use whatever field name you want in your model and provide a translation to the column name in the database. 2. You can specify the fields which have to be stored in the database and leave others which are only needed for working with the model, e.g You store the password in one field in its clear form and have a hashed field which will be stored in the database. I discussed this feature with Adrian and he was not disinclined to include such functionality into Searchlight.
Describe the bug Adding a field to an AbstractModel with no corresponding db column produces an error. I'm not sure if this is expected behaviour or not.
Error stacktrace
To reproduce Create a resource "colour":
with a db migration:
This should work fine: you can create, save, update, etc. Colours.
Then edit Colours.jl:
Then
julia > all(Colour)
orthrow the above error.
Expected behavior The object "red" is saved to the db, ignoring the field "other".
Additional context Please include the output of
julia> versioninfo()
andpkg> st
Additional context Please include the output of julia> versioninfo() and pkg> stand