Home » Database » DB_DataObject » Bug #3152
joinAdd requires join column to be in links.ini file
Details
| Submitted | 2005-01-10 15:33 UTC |
|---|---|
| From | mcraig at leadehealth dot com |
| Assigned | alan_k |
| Status | Closed |
| Package | DB_DataObject |
| PHP Version | 4.3.9 |
| OS | irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2005-01-10 15:33 UTC] mcraig at leadehealth dot com
Description:
------------
joinAdd can accept an argument called $joinCol, but if this column is not listed in the <DB>.links.ini file joinAdd will return an error.
[code that works. Diffed against 1.7.2]
2741a2742,2746
>
> if ($ofield === false && $joinCol) {
> $ofield = $joinCol;
> $tfield = $joinCol;
> }
After more thought, it seems that joinAdd() should be checking that both DOs do indeed have a column named {$joinCol}. Here is my stab at this, but I don't know the code well enough to do it right.
if ($ofield === false && $joinCol) {
if (isset($obj->$joinCol) && isset($this->$joinCol)) {
$ofield = $joinCol;
$tfield = $joinCol;
}
}
[2005-01-26 16:10 UTC] mcraig at leadehealth dot com
After further review, it looks like joinAdd provides very similar functionality (and works) when passed an array with settings as arg[0].
The hitch is that this method provides its own object, whereas the user may want to create the object and do some whereAdd-ing, orderBy-ing, etc. before joining it to another object.
Maybe this is intended, so that the user is only whereAdd-ing after the join has been done??
Anyway, my code would be inserted before line 2793 if it makes sense for the user to be able to create the objects ahead of time.
[2006-12-04 14:23 UTC] mcraig at leadehealth dot com
diff versus current cvs copy of DataObject.php:
--- DataObject.php 2006-12-04 09:11:39.000000000 -0500
+++ DataObject.mine.php 2006-12-04 09:15:13.000000000 -0500
@@ -3139,6 +3139,12 @@
}
}
+ // finally if these two table have column names that match do a join by default on them
+ if($ofield === false && $joinCol) {
+ $ofield = $joinCol;
+ $tfield = $joinCol;
+ }
+
/* did I find a conneciton between them? */
if ($ofield === false) {
Note: this will still return an SQL error if the programmer supplies a field name that is not present in both tables. Error checking possible as in the original comment might be nice so as to not break someone's code out there?