Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primary key incorrectly used instead of foreign keys, string as a foreign key is not permitted because of typehints #235

Open
genesiscz opened this issue Aug 14, 2019 · 0 comments

Comments

@genesiscz
Copy link

genesiscz commented Aug 14, 2019

Version: 3.0.2

Bug Description

... A clear and concise description of what the bug is. A good bug report shouldn't leave others needing to chase you up for more information.

First issue:

I have table cards, with columns id, user_guid, number
I have table users, with columns id, guid

I have a foreign key from cards.user_guid to users.guid

I want to use $cardActiveRow->user, but it tries to use its foreign key instead of correctly using foreign key. I can use $cardActiveRow->ref("user", "user_guid"), but I'd rather let it get determined by the foreign key.

So I solved it temorarily by changing primary key in users table to users.guid.

Second issue:

This problem is solved now, but not when I use related()

      $lastEntry = $user->related("work_hours", "user_guid")->order("id DESC")->limit(1)->fetch();

I get this error:

`TypeError

Argument 3 passed to Nette\Database\Table\Selection::getReferencingTable() must be of the type integer or null, string given, called in ..../vendor/nette/database/src/Database/Table/ActiveRow.php on line 141 `

The function signature is

public function getReferencingTable(string $table, string $column = null, int $active = null):

which prevents primary key to be anything else than int, while primary key can be either string, int or array. That would probably lead to another problem, function related calls $groupedSelection = $this->table->getReferencingTable($key, $throughColumn, $this[$this->table->getPrimary()]);

where $this->table->getPrimary() can return int, array or string. I guess there would be problem with passing an array as an array index.

The primary key being int was fixed by removing typehint from Selection.php function getReferencingTable in the third argument $active and also GroupedSelection.php function setActive.

I am not opening pull request because I am not totally sure I am correct in all these statements and would like a followup.

@genesiscz genesiscz changed the title Primary key as a string is not working because typehints Primary key incorrectly used instead of foreign keys, string as a foreign key is not permitted because of typehints Aug 14, 2019
@dg dg pinned this issue Aug 15, 2019
@dg dg unpinned this issue Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant