Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

LEFT join in api


#1

We’re looking to do a left join in our API so that a fetch of tests isn’t depdendent on a milestone being in place, however we do want to join to milestones when required.

	$this->db->select('milestones.name as milestone');	
	$this->db->from('tests');
	$this->db->join('milestones', 'milestones.id = runs.milestone_id');

How can I change the last “join” to a left join?

Thank you


#2

Hello Chris,

Thanks for your posting. There are two options here. There’s a simple ‘join_left’ method for this purpose or you can use the generic ‘query’ method (useful for more complex queries):

$query = $this->db->query( 'SELECT * FROM runs LEFT JOIN .. WHERE id = {0}', $some_run_id ); $runs = $query->result();

Possible arguments are replaced ({0}, {1}, {2}, …) and are also automatically quoted/escaped according to the format used by the underlying database (MySQL, SQL Server).

I hope this helps and please let me know in case you need anything else.

Regards,
Tobias