A booking can have a single customer and a customer can have a single "type".
3 Questions
1) Can FuelPHP do something similar to CakePHP with "Recursion" into foreign keyed tables, to X depth
2) How do I structure the models to allow allow recursion into relations
3) Find bookings where the customers_types.name = 'cash'
Your help would be much appreciated. It would be great for the documentation to cover this initial barrier to adoption with multiple examples (with schema)
class Model_Booking extends \Orm\Model{}
class Model_Customer extends \Orm\Model{}
class Model_Customers_Type extends \Orm\Model{}
CREATE TABLE `bookings` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
`customers_id` int(11) UNSIGNED NOT NULL ,
PRIMARY KEY (`id`),
FOREIGN KEY (`customers_id`) REFERENCES `customers` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
INDEX `customers_id` (`customers_id`) USING BTREE
);
CREATE TABLE `customers` (
`id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
`customers_types_id` int(11) UNSIGNED NOT NULL ,
PRIMARY KEY (`id`),
FOREIGN KEY (`customers_types_id`) REFERENCES `customers_types` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
INDEX `customers_types_id` (`customers_types_id`) USING BTREE
I don't know Cake, so I don't know what you mean by "Recursion".
You will have to setup the relation definition in your models, otherwise the ORM doesn't know how they are related.
So Model_Booking requires a belongs_to to Model_Customer, Model_Customer a has_many to Model_Booking and a belongs_to to Model_Customers_Type and Model_Customers_Type a has_many to Model_Customer.