Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

JTable doesn't update a field with a null value #364

Closed
zian974 opened this issue Sep 15, 2011 · 5 comments
Closed

JTable doesn't update a field with a null value #364

zian974 opened this issue Sep 15, 2011 · 5 comments

Comments

@zian974
Copy link

zian974 commented Sep 15, 2011

Hi
It is impossible for me to update a table with JTable and assign a null value for a field.
I think the problem is the processing of data in the bind () function of Table.php, more precisely in the foreach loop, at:
if (isset ($ src [$ k])) {
$ this-> $ k = $ src [$ k];
}
If the value is null, the assignment will never happen.

I need to put a null on a foreign key without any error FOREIGN_KEY_CHECKS

I tried replacing
if (isset ($ src [$ k]))
by
if (isset ($ src [$ k]) | | (is_null ($ src [$ k]) & & array_key_exists ($ k, $ src)))

and it works for now.

@elinw
Copy link
Contributor

elinw commented Jul 15, 2012

Wow I think this is happening for me as well when trying to save a blanked out article.

...

Actually I think this is because $updateNulls is set to false in the content table

Also #1077 although that has to do with a different table.

@mahagr
Copy link
Contributor

mahagr commented Jul 16, 2012

Actually this is feature (or issue) in bind() function itself, which prevents updating values that do not exist.

In PHP isset() returns false either if the value doesn't exist or is null. It's very useful for example when you may have optional input fields, which do not always come from GET or POST (are set but not defined). Changing this undocumented feature could potentially slightly break many extensions (and core) which rely on this feature.

If table needs some other behavior, I'd rather override the function with a version that works better for that table. Forcing bind() change to all tables may have catastrophic consequences on many extensions as it's breaking the current API.

@elinw
Copy link
Contributor

elinw commented Jul 17, 2012

Okay I found the problem in JTableContent which is that it was using !empty rather than isset for a condition and that was leading to other consequences

@dongilbert
Copy link
Contributor

So, has this been fixed in the CMS or a previous iteration of the Platform then?

@eddieajau
Copy link
Contributor

I'm sorry but we aren't accepting issues for this repository any more. Please see http://developer.joomla.org/cms/report-an-issue.html for how to report and issue for the CMS Platform.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants