|
@@ 1120-1134 (lines=15) @@
|
| 1117 |
|
* |
| 1118 |
|
* @return \Pulsar\Relation\Relation |
| 1119 |
|
*/ |
| 1120 |
|
public function belongsTo($model, $foreignKey = '', $localKey = '') |
| 1121 |
|
{ |
| 1122 |
|
if (!$foreignKey) { |
| 1123 |
|
$foreignKey = self::DEFAULT_ID_PROPERTY; |
| 1124 |
|
} |
| 1125 |
|
|
| 1126 |
|
// the default local key would look like `user_id` |
| 1127 |
|
// for a model named User |
| 1128 |
|
if (!$localKey) { |
| 1129 |
|
$inflector = Inflector::get(); |
| 1130 |
|
$localKey = strtolower($inflector->underscore($model::modelName())).'_id'; |
| 1131 |
|
} |
| 1132 |
|
|
| 1133 |
|
return new BelongsTo($this, $localKey, $model, $foreignKey); |
| 1134 |
|
} |
| 1135 |
|
|
| 1136 |
|
/** |
| 1137 |
|
* Creates the parent side of a Many-To-One or Many-To-Many relationship. |
|
@@ 1145-1159 (lines=15) @@
|
| 1142 |
|
* |
| 1143 |
|
* @return \Pulsar\Relation\Relation |
| 1144 |
|
*/ |
| 1145 |
|
public function hasMany($model, $foreignKey = '', $localKey = '') |
| 1146 |
|
{ |
| 1147 |
|
// the default foreign key would look like `user_id` |
| 1148 |
|
// for a model named User |
| 1149 |
|
if (!$foreignKey) { |
| 1150 |
|
$inflector = Inflector::get(); |
| 1151 |
|
$foreignKey = strtolower($inflector->underscore(static::modelName())).'_id'; |
| 1152 |
|
} |
| 1153 |
|
|
| 1154 |
|
if (!$localKey) { |
| 1155 |
|
$localKey = self::DEFAULT_ID_PROPERTY; |
| 1156 |
|
} |
| 1157 |
|
|
| 1158 |
|
return new HasMany($this, $localKey, $model, $foreignKey); |
| 1159 |
|
} |
| 1160 |
|
|
| 1161 |
|
/** |
| 1162 |
|
* Creates the child side of a Many-To-Many relationship. |