You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/1. Setup.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@
16
16
17
17
Once generated, the Record, Table and Validation models will not be overwritten by the generation tools. Developers can add any logic to these classes they desire.
18
18
19
-
The Definition models should only be modified the the generation tools and not updated by hand.
19
+
The Definition models should only be modified by the generation tools and not updated by hand.
20
20
21
21
Deletion of unused models should be done manually when the table is removed from the schema.
Copy file name to clipboardExpand all lines: docs/2. Active Record.md
+22-22Lines changed: 22 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -39,45 +39,45 @@ $customer->read($value);
39
39
40
40
### The basic CRUD methods:
41
41
-**insert**() or **create**()
42
-
* Adds the current record to the database. If the primary key already exists in the database, the insert fails. The auto increment primary key is updated with the value inserted.
43
-
* insert() returns the primary key value inserted, true if no primary key and the record was successfully inserted or false on error.
42
+
- Adds the current record to the database. If the primary key already exists in the database, the insert fails. The auto increment primary key is updated with the value inserted.
43
+
- insert() returns the primary key value inserted, true if no primary key and the record was successfully inserted or false on error.
44
44
-**insertOrUpdate**() or **save**()
45
-
* Will try to insert the record and on a duplicate key, will update the record with the current values.
46
-
* insertOrUpdate() returns the same values as insert().
47
-
* If the record only consists of primary keys, then this method is equivalent to insertOrIgnore().
45
+
- Will try to insert the record and on a duplicate key, will update the record with the current values.
46
+
- insertOrUpdate() returns the same values as insert().
47
+
- If the record only consists of primary keys, then this method is equivalent to insertOrIgnore().
48
48
-**insertOrIgnore**()
49
-
* Will try to insert the record and on a duplicate key, will not update.
50
-
* insertOrIgnore() returns the same values as insert().
49
+
- Will try to insert the record and on a duplicate key, will not update.
50
+
- insertOrIgnore() returns the same values as insert().
51
51
-**read**(int | string | array $find)
52
-
* Will try to load the first record matching the values passed in. If $find is an array, each key is used as a where condition equal to the value.
53
-
* If not an array, read uses $find to search by primary key.
54
-
* read() returns true on success or false if no match found
52
+
- Will try to load the first record matching the values passed in. If $find is an array, each key is used as a where condition equal to the value.
53
+
- If not an array, read uses $find to search by primary key.
54
+
- read() returns true on success or false if no match found
55
55
-**update**()
56
-
* Returns true if the record saved to the database.
56
+
- Returns true if the record saved to the database.
57
57
-**delete**()
58
-
* Deletes the record from the database. Defined child records are also deleted. You can overload delete() to do other custom work, like deleting an associated file if desired.
59
-
* delete() returns true on success
58
+
- Deletes the record from the database. Defined child records are also deleted. You can overload delete() to do other custom work, like deleting an associated file if desired.
59
+
- delete() returns true on success
60
60
61
61
### Other useful methods:
62
62
-**empty**()
63
-
* Returns true if all current values are the defaults
63
+
- Returns true if all current values are the defaults
64
64
-**loaded**()
65
-
* Returns true if actually read from the database, rather than being created programitically.
65
+
- Returns true if actually read from the database, rather than being created programitically.
66
66
-**reload**()
67
-
* Gets the most recent version from the database and overwrites existing data.
67
+
- Gets the most recent version from the database and overwrites existing data.
68
68
-**setEmpty**()
69
-
* Sets all the record values to defaults.
69
+
- Sets all the record values to defaults.
70
70
-**setFrom**(array)
71
-
* Sets fields from the key / value array passed in.
71
+
- Sets fields from the key / value array passed in.
72
72
73
73
### Advanced methods:
74
74
-**clean**()
75
-
* Can be overridden to perform actions before any write to the database.
75
+
- Can be overridden to perform actions before any write to the database.
76
76
-**setCustomValidator**(string $className)
77
-
* Overrides the default validator with this class name.
77
+
- Overrides the default validator with this class name.
* Validates the record. You can pass an optional method to validate against and original record if required by the validation.
80
-
* Returns an array of errors indexed by field name. Empty array means the record has correctly validated.
79
+
- Validates the record. You can pass an optional method to validate against and original record if required by the validation.
80
+
- Returns an array of errors indexed by field name. Empty array means the record has correctly validated.
81
81
82
82
## Related Records
83
83
Related records are indicated by field name ending in the id suffix (default: 'Id'). The field name before the 'Id' must be the same as the corresponding table name. See See [Virtual Fields](https://github.com/phpfui/ORM/blob/main/docs/5.%20Virtual%20Fields.md) for more advanced Related Records.
Copy file name to clipboardExpand all lines: docs/4. Cursors.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -49,5 +49,5 @@ foreach ($customerTable->getDataObjectCursor() as $record)
49
49
}
50
50
```
51
51
52
-
Please note that the [\PHPFUI\ORM\Record](http://phpfui.com/?n=PHPFUI%5CORM&c=Record) reuses the same **\PHPFUI\ORM\Record** instance to conserve memory, so they will need to be cloned if added to an array or cursor. **DataObjectCursor** and **ArrayCursor** return new objects.
52
+
**Please Note:** The [\PHPFUI\ORM\Record](http://phpfui.com/?n=PHPFUI%5CORM&c=Record) reuses the same **\PHPFUI\ORM\Record** instance to conserve memory, so they will need to be cloned if added to an array or collection. **DataObjectCursor** and **ArrayCursor** return new objects.
Copy file name to clipboardExpand all lines: docs/5. Virtual Fields.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
4
4
You can define virtual fields with get and set semantics for any **\App\Record** class. Virtual fields are evaluated before any database field, so you can override the database defaults if needed, or create new functionality.
5
5
6
-
Every **\App\Record** class has a static $virtualFields array defined. The key of the array is the name of the virtual key. The value for each virtual field is an array of strings. The first string is the virtual field class name. Subsequent parameters are are passed the the **getValue** and **setValue** methods.
6
+
Every **\App\Record** class has a static $virtualFields array defined. The key of the array is the name of the virtual key. The value for each virtual field is an array of strings. The first string is the virtual field class name. Subsequent parameters are are passed to the **getValue** and **setValue** methods.
7
7
8
8
Note that virtual fields are created each time they are accessed and not stored or cached in the [\PHPFUI\ORM\Record](http://phpfui.com/?n=PHPFUI%5CORM&c=Record) object. This means you can not change the virtual field on the **Record** object itself. You can only assign it to the Record object, which will store the value represented by the virtual field in the object, but not the virtual field itself.
9
9
@@ -88,7 +88,7 @@ class Order extends \Tests\App\Record\Definition\Order
88
88
}
89
89
```
90
90
91
-
By default, child records will be automatically deleted when the parent record is deleted. You can disable this functionality for a specific [\PHPFUI\ORM\Record](http://phpfui.com/?n=PHPFUI%5CORM&c=Record) class by setting the static property $deleteChildren to false, or using your own Children class.
91
+
By default, child records will be automatically deleted when the parent record is deleted. You can disable this functionality for a specific [\PHPFUI\ORM\Record](http://phpfui.com/?n=PHPFUI%5CORM&c=Record) class by setting the static property $deleteChildren to false, or by using your own Children class.
Copy file name to clipboardExpand all lines: docs/7. Validation.md
+13-1Lines changed: 13 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ if (! validationErrors)
16
16
$insertedId = $record->insert();
17
17
}
18
18
```
19
-
$validationErrors is an array indexed by field name containing an array of translated errors.
19
+
**$validationErrors** is an array indexed by field name containing an array of translated errors.
20
20
```php
21
21
foreach ($validationErrors as $field => $fieldErrors)
22
22
{
@@ -106,6 +106,18 @@ You want the name to be unique per division with in the company: *unique:company
106
106
You want the name to be unique for a specific type in the division: *unique:type,shoes,division*
107
107
You want the name to be unique for a specific type and division: *unique:type,shoes,division,10*
108
108
109
+
## NOT Operator
110
+
You can reverse any validator by preceding the validator with an ! (exclamation mark).
111
+
112
+
**Example:**
113
+
!starts_with:/ will fail if the field starts with a /
114
+
115
+
## OR Operator
116
+
You can validate a field if any one of the validators passes. Use the vertical bar (|) to separate validators. If one of the validators passes, then the the field is valid.
117
+
118
+
**Example:**
119
+
website|starts_with:/ will validate a fully qualified http url, or a root relative url.
120
+
109
121
## Optional Validation
110
122
You may need to do additional checks for a specific record type. A second parameter can be passed to the contructor which would represent the original values of the record.
* You can compare one field to another on the same Record with the field validators.
79
+
* You can compare one field to another on the same **\App\Record** with the field validators.
62
80
* * gt_field
63
81
* * lt_field
64
82
* * gte_field
65
83
* * lte_field
66
84
* * eq_field
85
+
* * neq_field
67
86
*
68
-
* Field validators take another field name as a parameter and perform the specified condition test. To compare against a specific value, use minvalue, maxvalue, or equal.
87
+
* Field validators take another field name as a parameter and perform the specified condition test. To compare against a specific value, use minvalue, maxvalue, equal or not_equal.
69
88
*
70
89
* ## Unique Parameters
71
90
* Without any parameters, the **unique** validator will make sure no other record has a matching value for the field being validated. The current record is always exempted from the unique test so it can be updated.
@@ -105,6 +124,17 @@
105
124
* You may need to do additional checks for a specific record type. A second parameter can be passed to the contructor which would represent the original values of the record.
106
125
*
107
126
* You can also pass an optional method to validate to perform more complex validation. If you use an optional method, the validator will not perform the standard validations unless you specifically call the validate() method again without the optional method parameter.
0 commit comments