Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-18-2007, 02:16 PM
Junior Member
 
Join Date: Aug 2007
Posts: 2
Default how to join tables?

hi,

im trying to learn zend framework a bit, because next work i will start working on big project based on zend framework.

i have created these tables:

Code:
employee: idemployee, name, age
Code:
project: idproject, info, responsible_employee_id
*

i managed to create models and reference map:

Code:
class Employee extends Zend_Db_Table_Abstract {
	protected $_name = "employee";
	protected $_primary = "idemployee";

	protected $_dependentTables = array("Projects");
}

class Project extends Zend_Db_Table_Abstract {
		protected $_name = "project";
		protected $_primary = "idproject";
		
		protected $_referenceMap = array(
			'ResponsibleEmployee' => array(
					'columns' => 'responsible_employee_id',
					'refTableClass' => 'Employee',
					'refColumns' => 'idemployee'
				)
		);
}
about my problem:

id like to select all projects, but i don't want to select responsible_employee_id, but his name (classic join)

i don't feel like being able to use referenceMap (which can be really hard work to create on big project) to automatically join these tables.

It wouldn't be so bad, if i could just add JOIN to fetchAll...

look:

Code:
(class Projects - model)
public function listing(){
  return $this->fetchAll()->toArray(); // I WANT TO ADD [JOIN] RIGHT HERE!
}
all i can do is:

Code:
$sql = $this->getAdapter()->select()->from("project")->join("employee", "project.responsible_employee = employee.idemployee", array("responsible_employee" => "name"));
return $this->getAdapter()->query($sql)->fetchAll();
when i do it like this, i don't use table object, so i don't use the model, so all the work (creating models, reference map) is useless..


zero0x
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:28 AM.