@@ 139-148 (lines=10) @@ | ||
136 | * |
|
137 | * @return \Magister\Services\Database\Elegant\Relations\HasOne |
|
138 | */ |
|
139 | public function hasOne($related, $foreignKey = null, $localKey = null) |
|
140 | { |
|
141 | $foreignKey = $foreignKey ?: $this->getForeignKey(); |
|
142 | ||
143 | $instance = new $related(); |
|
144 | ||
145 | $localKey = $localKey ?: $this->getKeyName(); |
|
146 | ||
147 | return new HasOne($instance->newQuery(), $this, $foreignKey, $localKey); |
|
148 | } |
|
149 | ||
150 | /** |
|
151 | * Define a one-to-many relationship. |
|
@@ 159-168 (lines=10) @@ | ||
156 | * |
|
157 | * @return \Magister\Services\Database\Elegant\Relations\HasMany |
|
158 | */ |
|
159 | public function hasMany($related, $foreignKey = null, $localKey = null) |
|
160 | { |
|
161 | $foreignKey = $foreignKey ?: $this->getForeignKey(); |
|
162 | ||
163 | $instance = new $related(); |
|
164 | ||
165 | $localKey = $localKey ?: $this->getKeyName(); |
|
166 | ||
167 | return new HasMany($instance->newQuery(), $this, $foreignKey, $localKey); |
|
168 | } |
|
169 | ||
170 | /** |
|
171 | * Create a new instance of the given model. |