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

Honor primary_key option in $belongs_to #365

Closed
wants to merge 1 commit into from
Closed

Honor primary_key option in $belongs_to #365

wants to merge 1 commit into from

Conversation

tuupola
Copy link
Contributor

@tuupola tuupola commented Sep 30, 2013

Fixes #364 primary_key support when using belongs_to relationship. With the following code:

class Car extends ActiveRecord\Model {
    static $belongs_to = array(
        array("alarm", "foreign_key" => "slug", "primary_key" => "slug")
    );
}

var_dump(Car::find($id)->alarm);

generated query before the patch is:

SELECT * FROM `alarms` WHERE `id`='something' LIMIT 0,1

after the patch it will be:

SELECT * FROM `alarms` WHERE `slug`='something' LIMIT 0,1

Fixes primary_key support when using belongs_to relationship (#364).
@tblanchard tblanchard mentioned this pull request Sep 30, 2013
@jpfuentes2
Copy link
Owner

Also great and similar to #368. Do you think you could add a quick test to this?

@tuupola
Copy link
Contributor Author

tuupola commented Nov 14, 2013

I actually looked at writing the tests. However I had hard time trying to understand the models and how to write the actual tests. I do know how to use PHPunit though :)

This pull request was closed.
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

Successfully merging this pull request may close these issues.

$belongs_to ignores primary_key option
3 participants