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

Strip schema from table for HasMany::their_name guess #1002

Merged
merged 3 commits into from
May 31, 2022

Conversation

samsouthardjr
Copy link
Contributor

@samsouthardjr samsouthardjr commented May 30, 2022

fixes #998

Comment on lines 32 to 36
$theirFieldName = $this->getModelTableString($ourModel);
if (($dbSepPos = strpos($theirFieldName, '.')) === false) {
$dbSepPos = -1;
}
$theirFieldName = substr($theirFieldName, $dbSepPos + 1) . '_' . $ourModel->id_field;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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;

Copy link
Member

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?

Copy link
Contributor Author

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).

@mvorisek mvorisek changed the title Strip out mydb from fallbackfield of a hasMany Strip schema from table for HasMany::their_name guess May 31, 2022
@mvorisek mvorisek merged commit 0401814 into atk4:develop May 31, 2022
@mvorisek
Copy link
Member

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

hasMany referencing a table in another db generates ciritcal error from lack of fallback field
2 participants