I'm trying to load a specific row from my database table with JTable. In my case i have 3 fields which is unique. In most cases, two of these fields will be a null value, while one will always have a value.

Here's an example of how i try to retrieve the row

$table = $this->getTable("table");
$table-load(['field1' =>'something', 'field2' => null, 'field3' => null]);

Through debugging i found out that joomla creates a query like field1 = 'something' AND field2 = '' AND field3 = '' which the fails to find the row with the null values.

Is there any workaround still using JTable, or do i have to use the database without JTable in this situation. I've read some places that they don't take a null value to consideration when querying, but still hope there is a solution

Here's a pastebin link of how the table look http://pastebin.com/TkKRG7FV

  • Using MySQL, you probably need the SQL to be field2 IS NULL. Did you find a solution? Commented Mar 24, 2017 at 14:19

2 Answers 2


May need some more detail on the db structure here. For example, if I understand you correctly that you have defined three fields in the db as 'must be unique,' any database that correctly follows the SQL specification will not let you put a null in any of those fields. (Some dbs allow it, but I'm not sure I'd depend upon that condition to continue.)

It would be useful to see the SQL that created the db table you're working with for this to help me get my mind around what you're trying to do.

  • Pastebin link for better view Here is an example of how my table looks like with valid data, @Arlen
    – Morten
    Commented Jul 22, 2015 at 7:21
  • What I find interesting in this is that the key defined as unique1 has three identical entries in your data ('test',NULL) while the key defined as unique2 also has three ('test', NULL) despite the fact they're defined as unique. Is the data actually stored in the table?
    – Arlen
    Commented Jul 22, 2015 at 18:01
  • Yes. When using null as value it is allowed to have multiple rows. The sql code i provided is live and running. However, if i updated field2 on a row and made it empty,but not null, it would be invalid to insert multiple rows with the same values, @Arlen
    – Morten
    Commented Jul 23, 2015 at 13:44

JTable::load() - Loads a row from the database and binds the fields to the object properties.

the Syntax is void load ($keys = NULL, $reset = true)

$keys is An optional primary key value to load the row by, or an array of fields to match.

What your doing is telling it to load the row that matches NULL

You need to set your default values in the JTable constructor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.