Skip to content

Commit 4beabbc

Browse files
author
rotexdegba
committed
Documentation in progress
1 parent 426570b commit 4beabbc

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

docs/more-about-models.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ This type of relationship requires at least three tables. Basically many records
9797
There a two recommended ways of defining relationships between Models.
9898

9999
1. After creating an instance of **\LeanOrm\Model** or any of its sub-classes, you should then go on to define relationships for that instance by calling the appropriate relationship defining methods (belongsTo, hasOne, hasMany or hasManyThrough) on that instance as needed. If you architect your application to only create a single Model instance for each table / view in your database, this approach would work well for you. It is recommended that you call the relationship definition methods immediately after creating each Model object. For example, if you manage objects in your application using a dependency injection container, then you should put the relationship definition method calls wherever each Model object is being created in your container setup code.
100-
> If you create more than one Model instance for each table / view in your database, then that means you will have to call the relationship definition methods on each Model instance for each database table / view, which will lead to lots of duplicate code scattered in your code-base. You should instead use the second method method of defining relationships described below if you have created individual Model classes (and optionally, Collection & Record Classes) for each database table / view you intend to access in your application
100+
> If you create more than one Model instance for each table / view in your database, then that means you will have to call the relationship definition methods on each Model instance for each database table / view, which will lead to lots of duplicate code scattered in your code-base. You should instead use the second method of defining relationships described below if you have created individual Model classes (and optionally, Collection & Record Classes) for each database table / view you intend to access in your application
101101
102102
2. Define relationships inside the constructor of each Model class (which should each be a sub-class of **\LeanOrm\Model**). If you intend to use direct instances of **\LeanOrm\Model** for each table / view in your database, this technique will not work for you, you will only be able to use option 1 above in that scenario. You only need to have created a unique Model class for each database table / view to use this option. You don't really need to have defined corresponding Collection & Record classes to pair with each Model class, it is perfectly fine for those Model classes to use
103103
**\LeanOrm\Model\Record** & **\LeanOrm\Model\Collection** to store data from the database.

0 commit comments

Comments
 (0)