I'm very new to ORM and I kind of understand the definition. Confusion starts when I try to implement relations.
Suppose I have these two tables.
Products table:
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| brand_id | int(11) | YES | | NULL | |
| name | varchar(100) | YES | | NULL | |
| description | text | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
Brand names table:
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(100) | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
How do I set up the models with $_has_many
$_belongs_to
so that when I do $product1 = Model_Product::find('first');
It also returns the name of the brand, like in SQL joins.
Or am I going about this the wrong way.
This doesn't have to be specific to fuelphp, I just want how to setup ORMs in this case.