Self-Referencing Relationships
I"m trying to figure out if any of the built-in relationships can be used to implement a self-referencing one-to-many relationship.
I have "Projects" which belong to "Customers" (Projects Module will have foriegn_key => customers_module).
Now a Project can have "related projects", which would be a one-to-many relationship back to it's own table. This is not a "foreign key" by definition, but foreign_key is the only relationship that represents a one-to-many. [side note: I have a tough time remembering that 'has_many' is a many-to-many relationship. In the above example I would naturally think "a customer has many projects"]
I haven't started building my modules yet, still drawing out the database relationships, but I'm thinking about the Model definitions as part of the modeling. Can I use something like
class Projects_model extends Base_module_model
{
public $foreign_keys = array('id' => array(FUEL_FOLDER => 'projects_model')));
function __construct()
{
parent::__construct('projects');
}
}
Comments
public $has_many = array('related_projects' =>'projects_model');
public $has_many = array( 'products' => array( 'model' => array(STORE_FOLDER => 'products_model') ), 'categories' => array( 'model' => array(STORE_FOLDER => 'categories_model') ), 'brands' => array( 'model' => array(STORE_FOLDER => 'brands_model') ), 'manufacturers' => array( 'model' => array(STORE_FOLDER => 'manufacturers_model') ) );