Strip schema from table for HasMany::their_name guess#1002
Strip schema from table for HasMany::their_name guess#1002mvorisek merged 3 commits intoatk4:developfrom
Conversation
src/Reference/HasMany.php
Outdated
| $theirFieldName = $this->getModelTableString($ourModel); | ||
| if (($dbSepPos = strpos($theirFieldName, '.')) === false) { | ||
| $dbSepPos = -1; | ||
| } | ||
| $theirFieldName = substr($theirFieldName, $dbSepPos + 1) . '_' . $ourModel->id_field; |
There was a problem hiding this comment.
| $theirFieldName = $this->getModelTableString($ourModel); | |
| if (($dbSepPos = strpos($theirFieldName, '.')) === false) { | |
| $dbSepPos = -1; | |
| } | |
| $theirFieldName = substr($theirFieldName, $dbSepPos + 1) . '_' . $ourModel->id_field; | |
| $theirFieldName = preg_replace('~^.+?\.~', '', $this->getModelTableString($ourModel)) . '_' . $ourModel->id_field; |
There was a problem hiding this comment.
is such guessing present solely for HasMany?
There was a problem hiding this comment.
I keep reminding myself to get better at regex.....and I was so focused on eliminating the exception that I never noticed getTheirFieldName being public so that I could use it in the tests.
Both items have been addressed. I did check, and only found that issue in HasMany -- it wouldn't apply to HasOne, which specifies our field name directly and -- unless you say otherwise -- uses the Id field of the other Model, so there's no guessing involved. The comments in getTheirFieldName seem to indicate that someone doesn't like the guessing at all, and that it may eventually go away. From my point of view, though, well-documented standards (i.e., using 'user_id' as the default field name for the id of a record in the User model) that make people's lives easier are a good thing, as long as they don't inhibit functionality (which this doesn't, since you can always override the field if you want to).
The pull request has been updated and passes all tests (the smoke test issues in other code remains, but that's from items not in this pull request).
|
Thank you |
fixes #998