I'm a newcomer to DB_Dataobject myself, and have had similar problems with linked tables.
I think you're correct in that whereAdd() only works within a single table. However, I don't think that joinAdd() will help either, this is for joining objects, not tables. Or at least if you are to get joinAdd() to work, you need to do more than just replacing whereAdd() with joinAdd() in the example code. However, if someone can correct me with some examples of code, I would be a happy man!
Anyway, to get around this, instead of whereAdd, I've had to use a raw query, e.g.
PHP Code:
function getPictures($str_conditions = '')
{
$obj_pictures = DB_DataObject::factory('pictures');
$str_query = "SELECT * FROM pictures, news_pictures WHERE news_pictures.news_id = {$this->news_id}) AND pictures.id = news_pictures.pictures_id";
if (!empty($str_conditions))
{
$str_query .= " " . $str_conditions;
}
$obj_pictures ->query("$str_query");
return $obj_pictures;
}
This works, but seems a bit "wrong" to me, as its not doing things in a very OO way, but I can't see how else to get this to work....
Anyway, if anyone has any better ideas
OR has any comments about my method, I'd love to hear from you!
I think it still looks fairly useful, though I think this does indeed weaken its value - after all what database *doesn't* have linked tables?
Hope this helps!
Paul
Bookmarks