Closed janosimas closed 2 years ago
Hmm, that's surprising as there are tests that should be ensuring that save and load are working properly on Many
. Are you able to provide an example source file/project that demonstrates the bug?
Which Many
method are you calling to try to retrieve the values and what return are you getting?
Let me clarify what I'm doing.
I'm creating a new MyType
and in the initialization fill up the new member
s. After this I try to save MyType
. Looks like here is my issue.
After this, I try to load with MyType::query().load(&conn).unwrap();
and I get an empty Many
. I checked the database and the link table has owner = -1
and has = -1
.
I uploaded the code I was working on: https://github.com/janosimas/code_as_db
You should be able to reproduce the issue with the current code from code_as_db_models/src/main.rs
Thanks. I took a look, and I see what's going on. There's actually two issues here
Many
field is saved (basically the Many
was trying to refer to the pk before it was known). I've just released 0.4.2
which addresses this.Parameter
objects were never saved by your code. The Many
doesn't own these -- the add
method only takes a reference. You should save them before adding them to the Many
-- otherwise they don't exist in the database at all. I'll look into whether it makes sense to make add
return an error for an object that has not yet been saved.Hey, thanks for for the quick responses for all my issues. 👍
I think an Error would be fine, it's better then a silent error.
I got a Type with a
Many<OtherType>
member but it doesn't persist the members.,I tried also overloading the
save
method and callingsave
on the member but when I try to save it I'm getting the error:value: NotInitialized
.