-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCommon.php
More file actions
35 lines (27 loc) · 827 Bytes
/
Copy pathCommon.php
File metadata and controls
35 lines (27 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
use CodeIgniter\Model;
if (! function_exists('get_foreign_key')) {
/**
* Get foreign key based on model info.
*/
function get_foreign_key(Model $model): string
{
$refObj = new ReflectionObject($model);
$refProp = $refObj->getProperty('table');
$table = $refProp->getValue($model);
$refProp = $refObj->getProperty('primaryKey');
$primaryKey = $refProp->getValue($model);
return singular($table) . '_' . $primaryKey;
}
}
if (! function_exists('get_primary_key')) {
/**
* Get primary key based on model info.
*/
function get_primary_key(Model $model): string
{
$refObj = new ReflectionObject($model);
$refProp = $refObj->getProperty('primaryKey');
return $refProp->getValue($model);
}
}