Skip to content

Commit 2cd1712

Browse files
committed
Cortex v1.5.0 Release
1 parent 613552c commit 2cd1712

File tree

3 files changed

+101
-9
lines changed

3 files changed

+101
-9
lines changed

changelog.txt

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
CHANGELOG - Cortex ORM
22

3-
1.4.2 (27.01.2017)
3+
1.5.0 (30.06.2017)
4+
* F3 3.6.2 compatibility fixes
5+
* new: Collection->contains method
6+
* new: Collection->compare method
7+
* allow a CortexCollection to be used as bind parameter for `IN` operators
8+
* allow to optionally set a table $charset
9+
* improved field whitelisting, #23 #24
10+
* include virtual fields in whitelist, #48
11+
* reduced schema queries
12+
* optimized table and field escaping in queries #46
13+
* use aliased table on join conditions
14+
* use class ttl defaults if any
15+
* added getRaw shortcut method
16+
* added space after `IN` group in query condition
17+
* added isSelf configuration existence check
18+
* Bug fix: issue with NULL-value as named bind parameter
19+
* Bug fix: table prefix on NULL comparison
20+
* Bug fix: invalid bind value on multiple rel counts
21+
22+
1.4.3 (01.03.2017)
23+
* Bug fix: fix NULL bind value issue, #40
24+
* Bug fix: fix NULL comparison, #40
25+
26+
1.4.2 (27.02.2017)
427
* new: self-referencing m:m relations
528
* new: support for NULL filter bind values (like `array('foo != ?',null)`)
629
* raised error level (from NOTICE to USER_ERROR)

lib/db/cortex.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
* https://github.com/ikkez/F3-Sugar/
1919
*
2020
* @package DB
21-
* @version 1.5.0-dev
22-
* @date 27.02.2017
21+
* @version 1.5.0
22+
* @date 30.06.2017
2323
* @since 24.04.2012
2424
*/
2525

readme.md

+75-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Cortex](https://dl.dropboxusercontent.com/u/3077539/_linked/cortex_icon.png?asd)
1+
![Cortex](https://ikkez.de/linked/cortex_icon.png)
22
***
33

44
### A general purpose Data-Mapper for the PHP Fat-Free Framework
@@ -386,15 +386,15 @@ To make relations work, you need to use a model class with field configuration.
386386

387387
This is how a field config looks with a relation:
388388

389-
![Cortex Rel 1](https://dl.dropboxusercontent.com/u/3077539/_linked/cortex-class-conf.png)
389+
![Cortex Rel 1](https://ikkez.de/linked/cortex-class-conf.png)
390390

391391
This creates an aggregation between Author and News, so
392392

393393
> One News belongs to one Author.
394394
395395
> One Author has written many News.
396396
397-
![UML 1](https://dl.dropboxusercontent.com/u/3077539/_linked/cortex-dia-1.png?)
397+
![UML 1](https://ikkez.de/linked//cortex-dia-1.png)
398398

399399
As a side note: `belongs-to-*` definitions will create a new column in that table, that is used to save the id of the counterpart model (foreign key field).
400400
Whereas `has-*` definitions are just virtual fields which are going to query the linked models by their own id (the inverse way). This leads us to the following configuration schema:
@@ -567,7 +567,7 @@ In case you want to bind a many-to-many relation to itself, meaning that you'd l
567567
</tr>
568568
</table>
569569

570-
A common scenario is where a `User` has friends and that relation target is also `User`. So in you would bind the relation to itself:
570+
A common scenario is where a `User` has friends and that relation target is also `User`. So it would bind the relation to itself:
571571

572572
```php
573573
namespace Model;
@@ -580,7 +580,7 @@ class User extends \DB\Cortex {
580580
}
581581
```
582582

583-
Because this is also a many to many relation, a pivor table is needed too. It's name is generated based on the table and fields name, but can also be defined as 3rd array parameter, i.e. `['\Model\User','friends','user_friends']`.
583+
Because this is also a many to many relation, a pivot table is needed too. Its name is generated based on the table and fields name, but can also be defined as 3rd array parameter, i.e. `['\Model\User','friends','user_friends']`.
584584

585585
![Cortex m:m self-ref](https://yuml.me/9467f355)
586586

@@ -755,6 +755,13 @@ Especially for value comparison, it's **highly recommended** to use placeholders
755755
* The `IN` operator usually needs multiple placeholders in raw PDO (like `foo IN (?,?,?)`). In Cortex queries you simply use an array for this, the QueryParser does the rest.
756756

757757
`array('foo IN ?', array(1,2,3))`
758+
759+
You can also use a CortexCollection as bind parameter. In that case, the primary keys are automatically used for matching:
760+
761+
```php
762+
$fruits = $fruitModel->find(['taste = ?','sweet']);
763+
$result = $userModel->find(['favorite_fruit IN ?',$fruits])
764+
```
758765

759766

760767
### Options
@@ -1371,6 +1378,14 @@ mixed get( string $key [, bool $raw = false ])
13711378
If `$raw` is `true`, it'll return the raw data from a field as is. No further processing, no relation is resolved, no get-event fired.
13721379
Useful if you only want the raw foreign key value of a relational field.
13731380

1381+
### getRaw
1382+
**Retrieve raw contents of key**
1383+
1384+
```php
1385+
mixed getRaw( string $key )
1386+
```
1387+
1388+
This is a shortcut method to `$mapper->get('key', TRUE)`.
13741389

13751390
### getFieldConfiguration
13761391
**Returns model $fieldConf array**
@@ -1614,6 +1629,60 @@ if ($result)
16141629

16151630
Use the `$reldepths` parameter to define what to cast, see [cast](#cast) method for details.
16161631

1632+
### compare
1633+
**compare collection with a given ID stack**
1634+
1635+
```php
1636+
array compare( array|CortexCollection $stack [, string $cpm_key = '_id'])
1637+
```
1638+
1639+
This method is useful to compare the current collection with another collection or a list of values that is checked for existence in the collection records.
1640+
1641+
In example you got a relation collection that is about to be updated and you want to know which records are going to be removed or would be new in the collection:
1642+
1643+
```php
1644+
$res = $user->friends->compare($newFriendIds);
1645+
if (isset($res['old'])) {
1646+
// removed friends
1647+
}
1648+
if (isset($res['new'])) {
1649+
// added friends
1650+
foreach($res['new'] as $userId) {
1651+
// do something with $userId
1652+
}
1653+
}
1654+
```
1655+
1656+
The compare result `$res` is an array that can contain the array keys `old` and `new`, which both represent an array of `$cpm_key` values.
1657+
1658+
NB: This is just a comparison - it actually does not update any of the collections. Add a simple `$user->friends = $newFriendIds;` after comparison to update the collection.
1659+
1660+
1661+
### contains
1662+
**check if the collection contains a record with the given key-val set**
1663+
1664+
```php
1665+
array contains( mixed|Cortex $val [, string $key = '_id' ])
1666+
```
1667+
1668+
This method can come handy to check if a collections contains a given record, or has a record with a given value:
1669+
1670+
```php
1671+
if ($user->friends && $user->friends->contains($newFriend)) {
1672+
$f3->error(400,'This user is already your friend');
1673+
return;
1674+
}
1675+
```
1676+
1677+
With custom compare key:
1678+
1679+
```php
1680+
if ($user->blocked_users->contains($currentUserId,'target')) {
1681+
// this user has blocked you
1682+
}
1683+
```
1684+
1685+
16171686
### expose
16181687
**return internal array representation**
16191688

@@ -1742,7 +1811,7 @@ Cortex currently only reflects to the most common use cases. If you need more ex
17421811

17431812
Anyways, I hope you find this useful. If you like this plugin, why not make a donation?
17441813

1745-
[![buy me a Beer](https://dl.dropboxusercontent.com/u/3077539/Beer/bdb_small_single.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=44UHPNUCVP7QG)
1814+
[![buy me a Beer](https://ikkez.de/linked/Beer/bdb_small_single.png)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=44UHPNUCVP7QG)
17461815

17471816
If you like to see Cortex in action, have a look at [fabulog](https://github.com/ikkez/fabulog "the new fabulous blog-ware").
17481817

0 commit comments

Comments
 (0)