I have a database table like this. `tables` `table_id` int(11) `table_name` varchar(255)
And this is my table_log database table. `table_log` `table_log_id` int(11) `table_from_id` int(11) COMMENT 'refer to tables.table_id` `table_to_id` int(11) COMMENT 'refer to tables.table_id'
I can use FuelPHP DB class like this. $result = \DB::select(\DB::expr('*, `table_from`.`table_name` AS `table_from_name`, `table_to`.`table_name` AS `table_to_name`')) ->as_object() ->from('table_log') ->join(\DB::expr('`' . \DB::table_prefix('tables') . '` AS `table_from`'), 'left') ->on(\DB::expr('`table_from`.`table_id`'), '=', 'table_log.table_from_id') ->join(\DB::expr('`' . \DB::table_prefix('tables') . '` AS `table_to`'), 'left') ->on(\DB::expr('`table_to`.`table_id`'), '=', 'table_log.table_to_id') ->where('customer_id', $customer_id) ->execute(); It is work fine with DB class. I just call when loop $row->table_from_name and $row->table_to_name.
How can i do this in ORM mode? Do i need to add manual select() like that? If not, How to write the relations property?
Just define your relations as you would always do? ORM doesn't care what the target table of the relation is. And if you have multiple relations, just use different relation names.