I need some help writing a ORM based retrieval of objects
So I have a table Organizations - and another additional tables Organizations_addresses. I have managed to create the "reverse join" on organization->id to organizations_addresses->org_id column.. So when I retrieve organizations I can get all the addresses associated with the organizations.
Now my organization_addresses table has a column called is_main which takes values 0 or 1.
Now when retrieving organization objects, I want to annotate the main site address..
something like this- >
Organization::objects->annotate(array(
'mainsite'=> addresses->filter(array('is_main' == 1))));
-but I can't find documentation on how to write the filter on "addresses" which are fields for Organization
my Organization model is like this->
$meta = array(
'table' => ORGANIZATION_TABLE,
'pk' => array('id'),
'joins' => array(
'users' => array(
'reverse' => 'User.org'
),
'cdata' => array(
'constraint' => array('id' => 'CompanyCdata.org_id')
),
'entries' => array(
'constraint' => array(
'id' => 'DynamicFormEntry.object_id',
"'O'" => 'DynamicFormEntry.object_type',
),
'list' => true,
),
'addresses' => array(
'reverse' => 'Companyaddress.cos',
)
),
where Companyaddress is a class
I find the ORM in osticket to be really powerful and interesting.. I would like to use this as much without having to write SQL queries.
Thanks for all the help.