Skip to content

Commit e314a33

Browse files
author
David Nahodyl
committed
added description for setting cross-database relationships
1 parent d37ec6b commit e314a33

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,30 @@ $person = FM::table('person')->where('nameFirst', 'Jaina')->first();
205205
// 10 most recent invoices
206206
$invoices = FM::layout('invoice')->where('customer_id', $customer->id)->orderByDesc('date')->limit(10)->get();
207207
```
208+
209+
## Relating Native Laravel models to FMModels
210+
It is possible to have relationships between native Laravel Model objects from your MySQL database and FMModels created from your FileMaker database. To do this, you will need to set up both connections in your `database.config` file and then make sure your models are pointing to the right connection by setting the `$connection` propety in your Model and FMModel classes.
211+
```
212+
protected $connection = 'theConnectionName';
213+
```
214+
215+
Once they're set correctly, you can create relationships, such as a belongsTo, by manually creating a new eloquent-filemaker belongsTo object and setting the appropriate keys.
216+
217+
Here is an example of setting a native Laravel User Model to belong to a FileMaker-based Company FMModel class.
218+
219+
User.php
220+
221+
```
222+
public function company()
223+
{
224+
return new \BlueFeather\EloquentFileMaker\Database\Eloquent\Relations\BelongsTo(Company::query(), $this, 'company_id', 'id', '');
225+
}
226+
227+
```
228+
229+
With this relationship created we can now get an FMModel of the Company the User belongs to like a normal relationship in a single database.
230+
231+
```
232+
// set $company to a FMModel of the User's Company
233+
$company = $user->company;
234+
```

0 commit comments

Comments
 (0)