I have some code which returns a query as_object()
This works, but I want to be able to get the _has_many() children from the returned object. Is this possible? Below is my code:
$query = DB::select_array(array('*'))
->from('job')
->as_object()
->where(blah = ?, value);
$results = $query->execute();
foreach ($results as $record) {
var_dump($record->mymodel);
}
Where mymodel :
<?php
class Model_Job extends Orm\Model
{
protected static $_table_name = 'job';
protected static $_primary_key = array('jobID');
protected static $_has_many = array('mymodel' => array(
'model_to' => 'Model_dbtable2',
'key_from' => 'jobID',
'key_to' => 'jobID'
));
}
It just returns null, no errors though.
Thanks in advance, Chris
So the object returned isn't one of my ORM classes? Its just a standard class. Okay, I thought it might be able to communicate and return my ORM class as the result.
Are they completely separate modules?
Thanks, Chris
The DBAL implemented by the DB classes is just a query builder. It runs queries and returns results, either as arrays or as standard objects.
You can use it to populate ORM model objects though, see http://docs.fuelphp.com/classes/database/usage.html#/results
Yeah I thought that's what I was doing, but I missed the object name from the as_object() call.
Never mind, I switched the code to use the ORM instead of the DB classes.
I have managed to get the relationships working quite nicely now.
Thanks for your help.