You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
module CreateTableColours
import SearchLight.Migrations: create_table, column, columns, primary_key, add_index, drop_table, add_indices
function up()
create_table(:colours) do
[
primary_key()
column(:name, :string)
column(:hex, :string)
]
end
add_index(:colours, :name)
end
function down()
drop_table(:colours)
end
end
This should work fine: you can create, save, update, etc. Colours.
julia > red = Colour(name = "red", hex = "FF0000", other = "foo")
Colour
| KEY | VALUE |
|----------------------|---------|
| hex::String | FF0000 |
| id::SearchLight.DbId | NULL |
| name::String | red |
| other::String | foo |
julia > save!(red)
throw 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()
and pkg> st
Additional context
Please include the output of
julia> versioninfo()
and
pkg> st
julia> versioninfo()
Julia Version 1.6.2
Commit 1b93d53fc4 (2021-07-14 15:36 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i3-6100 CPU @ 3.70GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
JULIA_REVISE = auto
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()
and
pkg> st
Additional context
Please include the output of
julia> versioninfo()
and
pkg> st
and
The text was updated successfully, but these errors were encountered: