nette / database

💾 A database layer with a familiar PDO-like API but much more powerful. Building queries, advanced joins, drivers for MySQL, PostgreSQL, SQLite, MS SQL Server and Oracle.
https://doc.nette.org/database
Other
502 stars 107 forks source link

Incomplete related data with StaticConventions #295

Closed peterpp closed 1 year ago

peterpp commented 1 year ago

Version: 3.1.7

Bug Description

Code

foreach ($explorer->table('book') as $book) {
    $tags = $book->related('book_tag')->select("tag.*")->fetchPairs('name');
}

does not return tags for all books if StaticConventions is used. It looks like the problem occurs if one tag is used with multiple books. Tags are returned only for one of those books.

Interesting is that if particular column is selected from tag table, it works fine:

foreach ($explorer->table('book') as $book) {
    $tags = $book->related('book_tag')->select("tag.name")->fetchPairs('name');
}

Expected Behavior

Tags for all books should be returned.

peterpp commented 1 year ago

Now I understand. The problem is that book_tag doesn't have the primary key id. But StaticConventions expects that every table has a id primary key.