* @return $uniqueValue Value of the unique key
*/
public final function getUniqueValue () {
- return $this->getCriteriaElemnent($this->getUniqueKey());
+ // Get primary key first
+ $primaryKey = trim($this->getCriteriaElemnent($this->getPrimaryKey()));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: tableName=' . $this->getTableName() . ',primaryKey=' . $primaryKey);
+
+ /*
+ * If this is not set, this could mean a badly written frontend as
+ * tables should always have a primary key.
+ */
+ if (empty($primaryKey)) {
+ // @TODO Issue a warning
+ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: Primary key not set for table ' . $this->getTableName() . ', please fix your table. Falling back to unique key ...');
+
+ // Get unique key
+ $uniqueKey = trim($this->getCriteriaElemnent($this->getUniqueKey()));
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: tableName=' . $this->getTableName() . ',uniqueKey=' . $uniqueKey);
+
+ // Is it empty, too?
+ if (empty($uniqueKey)) {
+ // Bad news, nothing is "unique" by design for this table
+ ApplicationEntryPoint::app_exit('Table ' . $this->getTableName() . ' has both no primary and unique key, but ' . __METHOD__ . ' was called. Please fix your table.');
+ } else {
+ // Return unique key
+ return $uniqueKey;
+ }
+ } else {
+ // Return primary key
+ return $primaryKey;
+ }
}
/**