Skip to content

Commit 5da0657

Browse files
committed
mostly docblock corrections; returning self from datamapper
1 parent 7228f4d commit 5da0657

File tree

6 files changed

+145
-79
lines changed

6 files changed

+145
-79
lines changed

phalcon/DataMapper/Query/AbstractQuery.zep

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ abstract class AbstractQuery
167167
/**
168168
* Resets the internal array
169169
*/
170-
public function reset()
170+
public function reset() -> <AbstractQuery>
171171
{
172172
let this->store["COLUMNS"] = [],
173173
this->store["FLAGS"] = [],
@@ -178,47 +178,89 @@ abstract class AbstractQuery
178178
this->store["ORDER"] = [],
179179
this->store["OFFSET"] = 0,
180180
this->store["WHERE"] = [];
181+
182+
return this;
181183
}
182184

183-
public function resetColumns()
185+
/**
186+
* Resets the columns
187+
*/
188+
public function resetColumns() -> <AbstractQuery>
184189
{
185190
let this->store["COLUMNS"] = [];
191+
192+
return this;
186193
}
187194

188-
public function resetFrom()
195+
/**
196+
* Resets the from
197+
*/
198+
public function resetFrom() -> <AbstractQuery>
189199
{
190200
let this->store["FROM"] = [];
201+
202+
return this;
191203
}
192204

193-
public function resetWhere()
205+
/**
206+
* Resets the where
207+
*/
208+
public function resetWhere() -> <AbstractQuery>
194209
{
195210
let this->store["WHERE"] = [];
211+
212+
return this;
196213
}
197214

198-
public function resetGroupBy()
215+
/**
216+
* Resets the group by
217+
*/
218+
public function resetGroupBy() -> <AbstractQuery>
199219
{
200220
let this->store["GROUP"] = [];
221+
222+
return this;
201223
}
202224

203-
public function resetHaving()
225+
/**
226+
* Resets the having
227+
*/
228+
public function resetHaving() -> <AbstractQuery>
204229
{
205230
let this->store["HAVING"] = [];
231+
232+
return this;
206233
}
207234

208-
public function resetOrderBy()
235+
/**
236+
* Resets the order by
237+
*/
238+
public function resetOrderBy() -> <AbstractQuery>
209239
{
210240
let this->store["ORDER"] = [];
241+
242+
return this;
211243
}
212244

213-
public function resetLimit()
245+
/**
246+
* Resets the limit and offset
247+
*/
248+
public function resetLimit() -> <AbstractQuery>
214249
{
215250
let this->store["LIMIT"] = 0,
216251
this->store["OFFSET"] = 0;
252+
253+
return this;
217254
}
218255

219-
public function resetFlags()
256+
/**
257+
* Resets the flags
258+
*/
259+
public function resetFlags() -> <AbstractQuery>
220260
{
221261
let this->store["FLAGS"] = [];
262+
263+
return this;
222264
}
223265

224266
/**

phalcon/Mvc/Model.zep

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3342,17 +3342,26 @@ abstract class Model extends AbstractInjectionAware implements EntityInterface,
33423342

33433343
/**
33443344
* Updates a model instance. If the instance doesn't exist in the
3345-
* persistence it will throw an exception. Returning true on success or
3346-
* false otherwise.
3345+
* persistence it will throw an exception. Returning `true` on success or
3346+
* `false` otherwise.
33473347
*
3348-
*```php
3349-
* // Updating a robot name
3350-
* $robot = Robots::findFirst("id = 100");
3348+
* ```php
3349+
* <?php
33513350
*
3352-
* $robot->name = "Biomass";
3351+
* use MyApp\Models\Invoices;
33533352
*
3354-
* $robot->update();
3355-
*```
3353+
* $invoice = Invoices::findFirst('inv_id = 4');
3354+
*
3355+
* $invoice->inv_total = 120;
3356+
*
3357+
* $invoice->update();
3358+
* ```
3359+
*
3360+
* !!! warning "NOTE"
3361+
*
3362+
* When retrieving the record with `findFirst()`, you need to get the full
3363+
* object back (no `columns` definition) but also retrieve it using the
3364+
* primary key. If not, the ORM will issue an `INSERT` instead of `UPDATE`.
33563365
*/
33573366
public function update() -> bool
33583367
{

phalcon/Mvc/Model/Criteria.zep

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ use Phalcon\Di\InjectionAwareInterface;
1717
use Phalcon\Mvc\Model\Query\BuilderInterface;
1818

1919
/**
20-
* Phalcon\Mvc\Model\Criteria
21-
*
2220
* This class is used to build the array parameter required by
2321
* Phalcon\Mvc\Model::find() and Phalcon\Mvc\Model::findFirst() using an
2422
* object-oriented interface.
2523
*
2624
* ```php
27-
* $robots = Robots::query()
28-
* ->where("type = :type:")
29-
* ->andWhere("year < 2000")
30-
* ->bind(["type" => "mechanical"])
25+
* <?php
26+
*
27+
* $invoices = Invoices::query()
28+
* ->where("inv_cst_id = :customerId:")
29+
* ->andWhere("inv_created_date < '2000-01-01'")
30+
* ->bind(["customerId" => 1])
3131
* ->limit(5, 10)
32-
* ->orderBy("name")
32+
* ->orderBy("inv_title")
3333
* ->execute();
3434
* ```
3535
*/
@@ -159,34 +159,36 @@ class Criteria implements CriteriaInterface, InjectionAwareInterface
159159

160160
/**
161161
* Sets the columns to be queried. The columns can be either a `string` or
162-
* an `array`. The string can specify one or more columns, separated by
163-
* commas, the same way that one uses the SQL select statement. You can
164-
* use aliases, aggregate functions etc. If you need to reference other
165-
* models you will need to reference them with their namespaces.
162+
* an `array` of strings. If the argument is a (single, non-embedded) string,
163+
* its content can specify one or more columns, separated by commas, the same
164+
* way that one uses the SQL select statement. You can use aliases, aggregate
165+
* functions, etc. If you need to reference other models you will need to
166+
* reference them with their namespaces.
166167
*
167168
* When using an array as a parameter, you will need to specify one field
168-
* per element. If a key is defined in our array, it will be used as the
169-
* alias in the query
169+
* per array element. If a non-numeric key is defined in the array, it will
170+
* be used as the alias in the query
170171
*
171172
*```php
172173
* <?php
173174
*
174175
* // String, comma separated values
175-
* $criteria->columns("id, name");
176+
* $criteria->columns("id, category");
176177
*
177178
* // Array, one column per element
178179
* $criteria->columns(
179180
* [
180-
* "id",
181-
* "name",
181+
* "inv_id",
182+
* "inv_total",
182183
* ]
183184
* );
184185
*
185-
* // Array, named keys. The name of the key acts as an alias (`AS` clause)
186+
* // Array with named key. The name of the key acts as an
187+
* // alias (`AS` clause)
186188
* $criteria->columns(
187189
* [
188-
* "name",
189-
* "number" => "COUNT(*)",
190+
* "inv_cst_id",
191+
* "total_invoices" => "COUNT(*)",
190192
* ]
191193
* );
192194
*
@@ -222,10 +224,11 @@ class Criteria implements CriteriaInterface, InjectionAwareInterface
222224
/**
223225
* Creates a query builder from criteria.
224226
*
225-
* ```php
226-
* $builder = Robots::query()
227-
* ->where("type = :type:")
228-
* ->bind(["type" => "mechanical"])
227+
* <?php
228+
*
229+
* $invoices = Invoices::query()
230+
* ->where("inv_cst_id = :customerId:")
231+
* ->bind(["customerId" => 1])
229232
* ->createBuilder();
230233
* ```
231234
*/
@@ -524,19 +527,21 @@ class Criteria implements CriteriaInterface, InjectionAwareInterface
524527
* Adds an INNER join to the query
525528
*
526529
*```php
530+
* <?php
531+
*
527532
* $criteria->innerJoin(
528-
* Robots::class
533+
* Invoices::class
529534
* );
530535
*
531536
* $criteria->innerJoin(
532-
* Robots::class,
533-
* "r.id = RobotsParts.robots_id"
537+
* Invoices::class,
538+
* "inv_cst_id = Customers.cst_id"
534539
* );
535540
*
536541
* $criteria->innerJoin(
537-
* Robots::class,
538-
* "r.id = RobotsParts.robots_id",
539-
* "r"
542+
* Invoices::class,
543+
* "i.inv_cst_id = Customers.cst_id",
544+
* "i"
540545
* );
541546
*```
542547
*/
@@ -601,25 +606,27 @@ class Criteria implements CriteriaInterface, InjectionAwareInterface
601606
* Adds an INNER join to the query
602607
*
603608
*```php
609+
* <?php
610+
*
604611
* $criteria->join(
605-
* Robots::class
612+
* Invoices::class
606613
* );
607614
*
608615
* $criteria->join(
609-
* Robots::class,
610-
* "r.id = RobotsParts.robots_id"
616+
* Invoices::class,
617+
* "inv_cst_id = Customers.cst_id"
611618
* );
612619
*
613620
* $criteria->join(
614-
* Robots::class,
615-
* "r.id = RobotsParts.robots_id",
616-
* "r"
621+
* Invoices::class,
622+
* "i.inv_cst_id = Customers.cst_id",
623+
* "i"
617624
* );
618625
*
619626
* $criteria->join(
620-
* Robots::class,
621-
* "r.id = RobotsParts.robots_id",
622-
* "r",
627+
* Invoices::class,
628+
* "i.inv_cst_id = Customers.cst_id",
629+
* "i",
623630
* "LEFT"
624631
* );
625632
*```
@@ -650,10 +657,12 @@ class Criteria implements CriteriaInterface, InjectionAwareInterface
650657
* Adds a LEFT join to the query
651658
*
652659
*```php
660+
* <?php
661+
*
653662
* $criteria->leftJoin(
654-
* Robots::class,
655-
* "r.id = RobotsParts.robots_id",
656-
* "r"
663+
* Invoices::class,
664+
* "i.inv_cst_id = Customers.cst_id",
665+
* "i"
657666
* );
658667
*```
659668
*/
@@ -808,10 +817,12 @@ class Criteria implements CriteriaInterface, InjectionAwareInterface
808817
* Adds a RIGHT join to the query
809818
*
810819
*```php
820+
* <?php
821+
*
811822
* $criteria->rightJoin(
812-
* Robots::class,
813-
* "r.id = RobotsParts.robots_id",
814-
* "r"
823+
* Invoices::class,
824+
* "i.inv_cst_id = Customers.cst_id",
825+
* "i"
815826
* );
816827
*```
817828
*/

phalcon/Mvc/Model/Query/Builder.zep

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -448,34 +448,36 @@ class Builder implements BuilderInterface, InjectionAwareInterface
448448

449449
/**
450450
* Sets the columns to be queried. The columns can be either a `string` or
451-
* an `array`. The string can specify one or more columns, separated by
452-
* commas, the same way that one uses the SQL select statement. You can
453-
* use aliases, aggregate functions etc. If you need to reference other
454-
* models you will need to reference them with their namespaces.
451+
* an `array` of strings. If the argument is a (single, non-embedded) string,
452+
* its content can specify one or more columns, separated by commas, the same
453+
* way that one uses the SQL select statement. You can use aliases, aggregate
454+
* functions, etc. If you need to reference other models you will need to
455+
* reference them with their namespaces.
455456
*
456457
* When using an array as a parameter, you will need to specify one field
457-
* per element. If a key is defined in our array, it will be used as the
458-
* alias in the query
458+
* per array element. If a non-numeric key is defined in the array, it will
459+
* be used as the alias in the query
459460
*
460461
*```php
461462
* <?php
462463
*
463464
* // String, comma separated values
464-
* $builder->columns("id, name");
465+
* $builder->columns("id, category");
465466
*
466467
* // Array, one column per element
467468
* $builder->columns(
468469
* [
469-
* "id",
470-
* "name",
470+
* "inv_id",
471+
* "inv_total",
471472
* ]
472473
* );
473474
*
474-
* // Array, named keys. The name of the key acts as an alias (`AS` clause)
475+
* // Array with named key. The name of the key acts as an
476+
* // alias (`AS` clause)
475477
* $builder->columns(
476478
* [
477-
* "name",
478-
* "number" => "COUNT(*)",
479+
* "inv_cst_id",
480+
* "total_invoices" => "COUNT(*)",
479481
* ]
480482
* );
481483
*

0 commit comments

Comments
 (0)