Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
PHP-MySQLi-Database-Class
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
PHP-MySQLi-Database-Class
Commits
25bf2fe6
Commit
25bf2fe6
authored
Jul 27, 2015
by
Alexander Butenko
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #273 from avbdr/master
Support for separate key definition in hasOne relation
parents
ba43d3bc
9cbabeb6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
5 deletions
+10
-5
dbObject.php
dbObject.php
+3
-4
dbObjectTests.php
tests/dbObjectTests.php
+5
-0
product.php
tests/models/product.php
+2
-1
No files found.
dbObject.php
View file @
25bf2fe6
...
...
@@ -139,17 +139,16 @@ class dbObject {
$modelName
=
$this
->
relations
[
$name
][
1
];
switch
(
$relationType
)
{
case
'hasone'
:
$key
=
isset
(
$this
->
relations
[
$name
][
2
])
?
$this
->
relations
[
$name
][
2
]
:
$name
;
$obj
=
new
$modelName
;
$obj
->
returnType
=
$this
->
returnType
;
$this
->
data
[
$name
]
=
$obj
->
byId
(
$this
->
data
[
$name
]);
return
$this
->
data
[
$name
];
return
$this
->
data
[
$name
]
=
$obj
->
byId
(
$this
->
data
[
$key
]);
break
;
case
'hasmany'
:
$key
=
$this
->
relations
[
$name
][
2
];
$obj
=
new
$modelName
;
$obj
->
returnType
=
$this
->
returnType
;
$this
->
data
[
$name
]
=
$obj
->
where
(
$key
,
$this
->
data
[
$this
->
primaryKey
])
->
get
();
return
$this
->
data
[
$name
];
return
$this
->
data
[
$name
]
=
$obj
->
where
(
$key
,
$this
->
data
[
$this
->
primaryKey
])
->
get
();
break
;
default
:
break
;
...
...
tests/dbObjectTests.php
View file @
25bf2fe6
...
...
@@ -129,6 +129,11 @@ if (!is_object ($product->data['userId'])) {
exit
;
}
$product
=
product
::
with
(
'user'
)
->
byId
(
5
);
if
(
!
is_object
(
$product
->
data
[
'user'
]))
{
echo
"Error in with processing in getOne object"
;
exit
;
}
$products
=
product
::
ArrayBuilder
()
->
with
(
'userId'
)
->
get
(
2
);
if
(
!
is_array
(
$products
[
0
][
'userId'
])
||
!
is_array
(
$products
[
1
][
'userId'
]))
{
...
...
tests/models/product.php
View file @
25bf2fe6
...
...
@@ -16,7 +16,8 @@ class product extends dbObject {
'productName'
=>
Array
(
'text'
,
'required'
)
);
protected
$relations
=
Array
(
'userId'
=>
Array
(
"hasOne"
,
"user"
)
'userId'
=>
Array
(
"hasOne"
,
"user"
),
'user'
=>
Array
(
"hasOne"
,
"user"
,
"userId"
)
);
public
function
last
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment