-
Notifications
You must be signed in to change notification settings - Fork 1
Foreign keys #2
Comments
Notation idea: Given this class class Car extends PersistentEntity {
public $id;
public $num_wheels;
public $brand;
protected $brand_id;
protected static $persistent_attributes = [
'id' => array(T::Integer, false, 'auto_increment'),
'num_wheels' => array(T::Integer),
'brand_id' => array(T::Timestamp),
];
protected static $table_name = 'CiviSaldo';
protected static $primary_key = ['id'];
} Define foreign keys as follows: protected static $foreign_keys = [['brand_id' => CarBrand::class, 'brand']]; I don't know how straightforward reading this would be, but it would be protected static $foreign_keys = [['fk' => 'brand_id', 'ref' => CarBrand::class, 'in' => 'brand']]; Same as previous. Or just protected static $foreign_keys = [['brand' => CarBrand::class]]; Where a hidden foreign key field is created in the database. |
The magic functions It would also be nice to be able to set a flag to join a referenced object on database level, thus limiting the amount of database queries. |
Other way around should also be possible $relations = [
'children' => Child::class
]; |
If you are going to embark in this: make sure you can model many-to-many relationships nicely. |
My idea for this would be using a $relations = [
'children' = [Child::class, ChildParentThrough::class]
]; Something like that. Where the through has to fk's an can contain arbritrary data. |
Make the framework understand foreign keys.
The text was updated successfully, but these errors were encountered: