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

Fixed #105 - Join table name not generated properly #109

Closed
wants to merge 2 commits into from
Closed

Fixed #105 - Join table name not generated properly #109

wants to merge 2 commits into from

Conversation

n-at-han-k
Copy link
Contributor

There was an issue with the has_many_through method. When you
passed it a model to associate with that had a namespace.
e.g. $post->has_many_through('\Blog\Models\Tag');

The error was that it wasn't correctly creating the table
name for the join.
e.g. post_tag was instead post_blog_models_tag
Thus results weren't being fetched.

Basically it was performing an algorithm to extract the class name from the namespace on one of the classes but not the other. So Paris would end up requesting a table like "post_namespace_namespace_tag" instead of "post_tag".

Fixes #105

passed it a model to associate with that had a namespace.
e.g. $post->has_many_through('\\Blog\\Models\\Tag');

The error was that it wasn't correctly creating the table
name for the join.
e.g. post_tag was instead post_blog_models_tag
Thus results weren't being fetched.
@n-at-han-k
Copy link
Contributor Author

The Travis CI build fails for 5.2 due to the unit test using namespaces.
Namespaces are needed in the tests because the bug only becomes apparent when using them in your project.
The actual fix doesn't break anything.

@treffynnon
Copy link
Collaborator

Thanks for the pull request. To get your tests to pass you need to change
the name of your phpunit file. I've created a rule so that if you append
Test53.php instead of just Test.php then it won't be run on anything less
than PHP 5.3. Please see phpunit.xml for where this rule is set. You'll
notice the ModelPrefixingTest53.php test file uses this format for example
as well.
On 19 Feb 2015 22:57, "Nathan Kidd" notifications@github.com wrote:

The Travis CI build fails for 5.2 due to the unit test using namespaces.
Namespaces are needed in the tests because bug only becomes apparent when
using them in your project.
The actual fix doesn't break anything.


Reply to this email directly or view it on GitHub
#109 (comment).

This is because the test is meant to test features of PHP 5.3+ so
obviously the cases will fail.
@n-at-han-k
Copy link
Contributor Author

Sorted it. Tests now pass.

@richp10
Copy link

richp10 commented Oct 16, 2016

I have run into this same problem - is there any chance this can be merged into master?

@treffynnon
Copy link
Collaborator

treffynnon commented Oct 16, 2016 via email

@treffynnon
Copy link
Collaborator

Merged into develop. Thanks.

@treffynnon treffynnon closed this Dec 14, 2016
Repository owner locked and limited conversation to collaborators Dec 14, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Neither short table name nor user defined table name used in has_many_through() method
3 participants