You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-18Lines changed: 24 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -394,26 +394,12 @@ It is possible to have relationships between native Laravel Model objects from y
394
394
protected $connection = 'theConnectionName';
395
395
```
396
396
397
-
Once they're set correctly, you can create relationships, such as a belongsTo, by manually creating a new eloquent-filemaker belongsTo object or importing a new trait and setting the appropriate keys.
397
+
Once the connections are set correctly, relationships from FMModel objects to sql-based Model objects should resolve correctly automatically. Relationships from regular `Model` objects to `FMModel` objects (version > 2.3.0 ) will require adding a new trait to your model class to enable the relationship to be created. For versions earlier than 2.3.0 or for more control over the relationship you can add a relationship connection manually using the examples below.
398
398
399
-
### Manually creating a relationship
400
-
401
-
Here is an example of setting a native Laravel User Model to belong to a FileMaker-based Company FMModel class.
402
-
403
-
```php
404
-
// User.php
405
-
406
-
class User extends Model
407
-
{
408
-
public function company()
409
-
{
410
-
return new \GearboxSolutions\EloquentFileMaker\Database\Eloquent\Relations\BelongsTo(Company::query(), $this, 'company_id', 'id', '');
411
-
}
412
-
}
413
-
```
399
+
you can create relationships, such as a belongsTo, by manually creating a new eloquent-filemaker belongsTo object or importing a new trait and setting the appropriate keys.
414
400
415
401
### Using trait to create a relationship (2.3.0+)
416
-
Here is an example of using the trait to create a native Laravel User Modelto belong to a FileMaker-based Company FMModel class.
402
+
The `HasHybridRelationships` trait allows the model to automatically resolve relationships from a `Model` to an `FMModel`. Here is an example of using the trait to create a native Laravel User `Model` in a SQL database to belong to a FileMaker-based Company `FMModel` class.
417
403
418
404
```php
419
405
// User.php
@@ -426,7 +412,8 @@ class User extends Model
426
412
427
413
public function company()
428
414
{
429
-
// This method looks at the related model and determines the correct relationship type
415
+
// The Company class is an FMModel and is stored in FileMaker
416
+
// The correct relationship will be resolved automatically thanks to the HasHybridRelationships trait
@@ -439,5 +426,24 @@ With this relationship created we can now get an FMModel of the Company the User
439
426
$company = $user->company;
440
427
```
441
428
429
+
### Manually creating a relationship
430
+
431
+
Using the `HasHybridRelationships` trait is the easiest way to create relationships between native Laravel models and FMModels. However, if you are using an older version of Eloquent FileMaker or want to manually manage the relationships you can establish the relationship by using the Eloquent FileMaker version of the relationship type. Each valid relationship type will be available under the `\GearboxSolutions\EloquentFileMaker\Database\Eloquent\Relations\` namespace.
432
+
433
+
Here is an example of setting a native Laravel User Model to belong to a FileMaker-based Company FMModel class.
434
+
435
+
```php
436
+
// User.php
437
+
438
+
class User extends Model
439
+
{
440
+
public function company()
441
+
{
442
+
// The Company class is an FMModel and is stored in FileMaker
443
+
return new \GearboxSolutions\EloquentFileMaker\Database\Eloquent\Relations\BelongsTo(Company::query(), $this, 'company_id', 'id', '');
444
+
}
445
+
}
446
+
```
447
+
442
448
## License
443
449
Eloquent-FileMaker is open-sourced software licensed under the MIT license.
0 commit comments