For the 1.0 release we'll need relations. It should be functioning something like this:
class User {
/**
* The `address` table should have a `user_id` column which matches te primary key of the `user` table
* The `user_id` column should have a unique constraint
*
* @return HasOne
*/
public function address() {
return $this->hasOne(Address::class);
}
/**
* The `preference` table should have a `user_id` column which mathces the primary key of the `user` tale
*
* @return HasMany
*/
public function preferences() {
return $this->hasMany(Preference::class);
}
/**
* A user belongs to many roles
* The junction table `role_user` should be determined by the policy
* The junction table should have a `user_id` column which matches the primary key of the `user` table
* The junction table should have a `role_id` column which matches the primary key of the `role` table
* The foreign keys should be determined by the policy
*
* @return BelongsToMany
*/
public function roles() {
return $this->belongsToMany(Role::class)
}
}
class Address {
/**
* The `address` table should have a `user_id` column which matches te primary key of the `user` table
* The `user_id` column should have a unique constraint
*
* @return BelongsToOne
*/
public function user() {
return $this->belongsToOne(User::class);
}
}
class Preference {
/**
* The `preference` table should have a `user_id` column which mathces the primary key of the `user` tale
*
* @return BelongsToOne
*/
public function user() {
return $this->belongsToOne(User::class);
}
}
class Role {
/**
* A role belongs to many users
* The junction table `role_user` should be determined by the policy
* The junction table should have a `user_id` column which matches the primary key of the `user` table
* The junction table should have a `role_id` column which matches the primary key of the `role` table
* The foreign keys should be determined by the policy
*
* @return BelongsToMany
*/
public function users() {
return $this->belongsToMany(User::class)
}
}
[x] Policy: add junction table method
[x] Policy: add foreign key method
[x] Relation: Create a relation class like the policy class which should be responsible for instantiating the relation objects
[x] Create relation classes for the different relations
[x] HasOne: one-to-one represents the owning side of the relation
[x] BelongsTo(One): one-to-one represents the oppsite of HasOne
[x] HasMany: one-to-many represents the 'one' side
[x] BelongsToMany: many-to-many represents both sides of the relation
For the 1.0 release we'll need relations. It should be functioning something like this: