Jaxel
Well-known member
So entities are a bit confusing to me. I just got used to now XF1 did things, and now XF2 is so completely different. It's my understanding that an "Entity" is basically a combination of the Models and DataWriters of XF1? Is that right? Anyways... the dev guide says things are self-explanatory, but not for me... there seems to be a lot of information unexplained. I'm a little stupid when it comes to the ground level stuff; I'm more into the weeds of of the logic, and less about the semantics.
Here is my first Entity:
My main questions are related to getters, behaviors and relations... mainly, what do they do? What options do I have?
Looking at some entities that already exist, there are some options I've seen, that I don't understand what they do. I see in the relations section, some items that have complicated conditions, "key", and "with"; but no documentation. As well, in what situations would you want to use "self::TO_MANY"? Is it a left to right, or a right to left relation? For instance, in my code above, if a CatLink can only link to one Category, but a Category can link to many CatLinks; which type should I use? As well, in my schema, CatLinks are unique by dual columns category_id+game_id, not to a single Category or Game... so does that change the semantics even more?
Here is my first Entity:
Code:
<?php
namespace EWR\Rio\Entity;
use XF\Mvc\Entity\Structure;
class CatLink extends \XF\Mvc\Entity\Entity
{
public static function getStructure(Structure $structure)
{
$structure->table = 'EWRrio_catlinks';
$structure->shortName = 'EWR\Rio:CatLink';
$structure->primaryKey = 'catlink_id';
$structure->columns = [
'catlink_id' => ['type' => self::UINT, 'autoIncrement' => true],
'category_id' => ['type' => self::UINT, 'required' => true]
'game_id' => ['type' => self::UINT, 'required' => true]
];
$structure->getters = [];
$structure->relations = [
'Category' => [
'entity' => 'EWR\Rio:Category',
'type' => self::TO_ONE,
'conditions' => 'category_id',
'primary' => true,
],
'Game' => [
'entity' => 'EWR\Rio:Game',
'type' => self::TO_ONE,
'conditions' => 'game_id',
'primary' => true
],
];
return $structure;
}
}
My main questions are related to getters, behaviors and relations... mainly, what do they do? What options do I have?
Looking at some entities that already exist, there are some options I've seen, that I don't understand what they do. I see in the relations section, some items that have complicated conditions, "key", and "with"; but no documentation. As well, in what situations would you want to use "self::TO_MANY"? Is it a left to right, or a right to left relation? For instance, in my code above, if a CatLink can only link to one Category, but a Category can link to many CatLinks; which type should I use? As well, in my schema, CatLinks are unique by dual columns category_id+game_id, not to a single Category or Game... so does that change the semantics even more?