Skip to content

$has_many ignores primary_key option when eager loading  #366

@tuupola

Description

@tuupola

With the following code:

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


$foo = Car::find($id)->residual_values;

$bar = Car::find($id, array(
    "include" => array("residual_values")
));

The generated queries will be:

SELECT * FROM `residual_values` WHERE `slug`='something'
SELECT * FROM `residual_values` WHERE `slug` IN(119)

Eager loading gets it wrong. Queries should be the same:

SELECT * FROM `residual_values` WHERE `slug`='something'
SELECT * FROM `residual_values` WHERE `slug`='something'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions