Open h4kuna opened 7 years ago
I only find where can be bug, because i don't undestand of context or if is good way for fix. I try manuly replace files.
a get new exception. Fatal error: Uncaught exception 'Nette\MemberAccessException' with message 'Cannot read an undeclared column ':response_files.responses_id'.' in /usr/share/nginx/html/nette-database/src/Database/Table/ActiveRow.php on line 299 Yes :response_files.responses_id doesn't exist, but why it is need? I try prepare PR for all the time, but now i haven't solution. :)
I try new way how to fix. Update ActiveRow
# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- a/src/Database/Table/ActiveRow.php
+++ b/src/Database/Table/ActiveRow.php
@@ -150,6 +150,10 @@
*/
public function related($key, $throughColumn = NULL)
{
+ if ($throughColumn && substr($throughColumn, 0, 1) === ':') {
+ return $this->getTable()->createSelectionInstance($key)
+ ->where($throughColumn, $this->getPrimary());
+ }
$groupedSelection = $this->table->getReferencingTable($key, $throughColumn, $this[$this->table->getPrimary()]);
if (!$groupedSelection) {
throw new Nette\MemberAccessException("No reference found for \${$this->table->getName()}->related($key).");
Now can return Selection and it works perfect.
$responses = $context->table('responses')->where('id', 16)->fetch();
$files = $responses->related('files', ':response_files.responses_id');
foreach ($files as $file) {
dump($file);
}
Is it possible?
It is similar as
$responses = $context->table('responses')->where('id', 16)->fetch();
$files = $responses->getTable()->createSelectionInstance('files')->where(':response_files.responses_id', $responses->id);
foreach ($files as $file) {
dump($file);
}
But method ActiveRow::getTable() has annotation internal.
Is it possible?
Probably not, because calling createSelection() will destry contant-number-of-queries feature.
Description
Hi,
if i create relation over relation table, then condition prefix is bad generated. Same problem is in ORDER BY.
I know response.id where is 1:n relation to response_files and here is only 1:1 relation to table files.
Output sql is right but, in condition WHERE table
files
is bad.sql schema
prepare environment
php script run.php