[4.0] Error when saving an object in JTable->save() #33840
Replies: 16 comments 13 replies
-
The use of @Hackwar Since the original PR #25761 was yours: Could you check this issue here and let us know your thoughts on it? Thanks in advance. |
Beta Was this translation helpful? Give feedback.
-
I don't think the PRs are related. For this requirement, @korenevskiy has can implement The problem here is that look like he does not want to do that and want Joomla to do all magic things to set default values for these fields automatically. From what I can see, it is not possible, at least for our current code. |
Beta Was this translation helpful? Give feedback.
-
@joomdonation So we close it as expected behaviour? |
Beta Was this translation helpful? Give feedback.
-
At least this is not an issue. Move to discussion if needed but from what I see, this is something we won't support. |
Beta Was this translation helpful? Give feedback.
-
Of course, this is solved with a crutch. |
Beta Was this translation helpful? Give feedback.
-
We still have to support PHP versions lower than 8 with Joomla 4. |
Beta Was this translation helpful? Give feedback.
-
@richard67 |
Beta Was this translation helpful? Give feedback.
-
I move this to discussions. |
Beta Was this translation helpful? Give feedback.
-
Then let's discuss the topic of how to do it, and not what it is necessary for. |
Beta Was this translation helpful? Give feedback.
-
The I propose the following solution. edit method
|
Beta Was this translation helpful? Give feedback.
-
I don't get the problem, if you bind a value to the table only the set values are written to the database or not? |
Beta Was this translation helpful? Give feedback.
-
@HLeithner @richard67 $fields = JTable->getFields(false); But why does the constructor load fields from the database and their default values, but the constructor does not assign default values to the table fields? |
Beta Was this translation helpful? Give feedback.
-
@HLeithner @richard67 @joomdonation Crutches will be installed, as long as it works, there is no question of typization the code.. |
Beta Was this translation helpful? Give feedback.
-
@richard67 @joomdonation @HLeithner Tell me please.
Dear colleagues. Please tell me to which repository should I do PR? |
Beta Was this translation helpful? Give feedback.
-
I will do this for 4.0-dev. |
Beta Was this translation helpful? Give feedback.
-
@joomdonation @HLeithner |
Beta Was this translation helpful? Give feedback.
-
I created a class
Loading JSON.
$object = json_decode($json, true);
Save data.
But data with empty values is saved to the database.
I spent a lot of time looking for the problem.
Even the site //php.net does not report PHP restrictions
The
Table->bind()
method has exactly the same behavior.The fact is that the
Table->GetProperties()
method has the codeget_object_vars()
.But the
get_object_vars()
function has limitations.For the function to work, it needs to get the property names with their own values. But there are no default values in the JTable Products class.
The
Table->Bind()
method and theTable->Save()
method do not use the original property values at all, these methods only set new values with properties.This problem is a bug of PHP developers. After all, it is obvious that int fields by definition should have a default value of 0.
Why do I need to set default property values if I'm going to explicitly override the properties (in
Table->save()
andTable->bind()
)?I suggest using something else in the
Table->GetProperties()
method instead ofget_object_vars()
.However, the
Table-set()
method works in all cases, and theTable->save()
method should also work in all binding cases.Beta Was this translation helpful? Give feedback.
All reactions