emiya
Member
Hello!
First of all, I'll show you my current situation.
I have 2 tables which kinda looks like:
Transactions
Codes
Now I have created 2 entities for the above tables and for the "Transactions" entity I have created a relation to the "Codes" table.
My problem is if I want to get all items from "Transactions" I also want every code related to each transaction. Currently I only receive one item from "Codes".
This is my relationship from "Transactions"
and here is a snippet of the foreach loop
The dump of $test.Codes
I hope you understand my situation and are willing to help me.
First of all, I'll show you my current situation.
I have 2 tables which kinda looks like:
Transactions
payment_id | user_id | username | date |
---|---|---|---|
1 | 1 | admin | timestamp |
Codes
code_id | payment_id | code | amount |
---|---|---|---|
1 | 1 | 83674538954 | 10.00 |
2 | 1 | 09574098574 | 10.00 |
3 | 1 | 89498365439 | 10.00 |
Now I have created 2 entities for the above tables and for the "Transactions" entity I have created a relation to the "Codes" table.
My problem is if I want to get all items from "Transactions" I also want every code related to each transaction. Currently I only receive one item from "Codes".
This is my relationship from "Transactions"
PHP:
$structure->relations = [
'Codes' => [
'entity' => 'foo\foo:Codes',
'type' => self::TO_ONE,
'conditions' => 'payment_id'
]
];
$structure->defaultWith = ['Codes'];
and here is a snippet of the foreach loop
HTML:
<xf:foreach loop="$codeList" value="$test" key="$key">
<tr>
<td>{$test.username}</td>
<td>{$test.title}</td>
<td></td> <!-- This should be all items from "[B]Codes[/B]" that belong to the Payment_id, but I only get one item
<td>{$test.Codes.amount}</td>
<td>{$test.created}</td>
<td>{$test.complete}</td>
<td></td>
</tr>
</xf:foreach>
The dump of $test.Codes
JSON:
Codes {#333 ▼
#_getterCache: []
#_valueCache: []
#_structure: Structure {#336 ▶}
#_em: Manager {#236 ▶}
-_uniqueEntityId: 6
#rootClass: "Foo\Foo\Entity\Codes"
#_useReplaceInto: false
#_newValues: []
#_values: array:5 [▼
"code_id" => 1
"payment_id" => 3
"code" => "83674538954"
"amount" => "10.00"
]
#_relations: []
#_previousValues: []
#_options: []
#_deleted: false
#_readOnly: false
#_writePending: false
#_writeRunning: false
#_errors: []
#_whenSaveable: []
#_cascadeSave: []
#_behaviors: null
}
I hope you understand my situation and are willing to help me.