-
Notifications
You must be signed in to change notification settings - Fork 47
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
Strip schema from table for HasMany::their_name guess #1002
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is such guessing present solely for HasMany?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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