Skip to content

Commit 0b5c7dc

Browse files
committed
extended instructions for relationships and the new trait
1 parent af0ec96 commit 0b5c7dc

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

README.md

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -394,26 +394,12 @@ It is possible to have relationships between native Laravel Model objects from y
394394
protected $connection = 'theConnectionName';
395395
```
396396

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.
398398

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.
414400

415401
### Using trait to create a relationship (2.3.0+)
416-
Here is an example of using the trait to create a native Laravel User Model to 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.
417403

418404
```php
419405
// User.php
@@ -426,7 +412,8 @@ class User extends Model
426412

427413
public function company()
428414
{
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
430417
return $this->belongsTo(Company::class, 'company_id', 'id');
431418
}
432419
}
@@ -439,5 +426,24 @@ With this relationship created we can now get an FMModel of the Company the User
439426
$company = $user->company;
440427
```
441428

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+
442448
## License
443449
Eloquent-FileMaker is open-sourced software licensed under the MIT license.

0 commit comments

Comments
 (0)