Skip to content
This repository has been archived by the owner on Jan 30, 2022. It is now read-only.

Commit

Permalink
Its more logical to create the model first when trying to understand …
Browse files Browse the repository at this point in the history
…how it works
  • Loading branch information
Francois Faubert committed Oct 6, 2016
1 parent 75c401a commit 9231fb6
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@ You models will then feed an instance of the service class when a `query()` invo

In this example we will create a Strata Model named 'Rates' that connects to an external MySQL database using a custom service.

First start by creating a file under `~/src/Model/Service/` named `RatesService.php`.

The file should contain connection information as well optional pre-formatted queries. It also has the mandate of returning `RateEntity` elements upon each queries' `fetch()`.
First, create a new `Rate` Model using Strata's `generate` command.

~~~ bash
$ ./strata generate model rate
~~~


Then manually create a new connection service class under `~/src/Model/Service/` named `RatesService.php`.

The file should contain connection information as well optional pre-formatted queries. It also has the job of returning `RateEntity` elements upon each queries' `fetch()`.

~~~ php
<?php
Expand Down Expand Up @@ -53,7 +61,7 @@ class RatesService extends MysqlConnector {
return $formatted;
}

public function getByLocationCode($locationCode)
public function findByLocationCode($locationCode)
{
return $this
->select("r.*")
Expand All @@ -63,7 +71,7 @@ class RatesService extends MysqlConnector {
->fetch();
}

public function getWithCategories()
public function findWithCategories()
{
return $this
->select("r.*")
Expand All @@ -75,13 +83,6 @@ class RatesService extends MysqlConnector {
~~~


Secondly, create a new `Rate` Model using Strata's `generate` command.

~~~ bash
$ ./strata generate model rate
~~~


Finally configure the class to use the new service as query adapter.

~~~ php
Expand Down

0 comments on commit 9231fb6

Please sign in to comment.