Can I tell Gas that I only want the ‘id’ and ‘username’ fields from the users table and the ‘id’ and ‘email’ field from the emails table? I found out that I can add ->select() to tell Gas what to get from the users table, but what about the email table?
This is what added on in the latest version. You could have something like :
function _init()
{
// Define relationships
self::$relationships = array(
'wife' => ORM::has_one('\\Model\\Wife', array('select:id,name')),
'job' => ORM::has_many('\\Model\\Job\\User => \\Model\\Job', array('select:id,name')),
);
// Define fields definition
self::$fields = array(
'username' => ORM::field('char[10]', array('required', 'callback_username_check')),
);
}In user table, so when you load your related entity, you could include some pre-process query you want (select, order_by and limit). Look around at the repo, in the develop branch within unit test section for furthermore usage.
Also, can I eager load multiple levels? For example if there is another m:m relationship after emails?
In latest version, sure. You could have something like :
// Relationship statement block….
'acl' => ORM::has_many('\\Model\\Role\\User => \\Model\\Role <= \\Model\\Acl\\Role => \\Model\\Acl', array('select:id,name')),for example, which actually connectiong ‘user’ table in several tier level of tuple(s) to reach the ‘acl’ table.