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

Use the name of the table to create the relation #544

Merged
merged 17 commits into from
Nov 22, 2023

Conversation

thiagotalma
Copy link
Contributor

Q A
Is bugfix?
New feature?
Breaks BC?

Use the real name of the table to create the relationship when there is a composite primary key.

Prevents the generation of random relationship names.

Turn this:

<?php

(...)

/**
 *
 * @property int $id
 * @property int $employee_id
 *
 * @property Employee $employee
 * @property Route $employee0 <---
 */
class Company extends \yii\db\ActiveRecord
{
    (...)

    /**
     * Gets query for [[Employee]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getEmployee()
    {
        return $this->hasOne(Employee::class, ['id' => 'employee_id']);
    }

    /**
     * Gets query for [[Employee0]]. <---
     *
     * @return \yii\db\ActiveQuery
     */
    public function getEmployee0() /* <--- */
    {
        return $this->hasOne(Route::class, ['employee_id' => 'employee_id', 'id' => 'route_id']);
    }
}

Into this:

<?php

(...)

/**
 *
 * @property int $id
 * @property int $employee_id
 * @property string $route_id
 *
 * @property Employee $employee
 * @property Route $route <---
 */
class Company extends \yii\db\ActiveRecord
{
    (...)

    /**
     * Gets query for [[Employee]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getEmployee()
    {
        return $this->hasOne(Employee::class, ['id' => 'employee_id']);
    }

    /**
     * Gets query for [[Route]]. <---
     *
     * @return \yii\db\ActiveQuery
     */
    public function getRoute() /* <--- */
    {
        return $this->hasOne(Route::class, ['employee_id' => 'employee_id', 'id' => 'route_id']);
    }
}

Copy link

what-the-diff bot commented Nov 21, 2023

PR Summary

  • Update to CHANGELOG.md
    The document containing a record of all notable changes made to the project has been updated.

  • Improvement to Relation Creation
    We've made a modification so that creating relations now utilizes the name of the table. This change should enhance the precision and understanding of the process.

@bizley
Copy link
Member

bizley commented Nov 21, 2023

Since this just brings back the removed code please don't update the changelog.

@thiagotalma
Copy link
Contributor Author

Done.

@bizley, the last launch was in May. In your opinion, is it time to launch a new release?

@bizley
Copy link
Member

bizley commented Nov 22, 2023

Possibly, we need to check the current milestone state.

@bizley bizley added this to the 2.2.7 milestone Nov 22, 2023
@bizley bizley merged commit c7533e5 into yiisoft:master Nov 22, 2023
11 checks passed
@thiagotalma thiagotalma deleted the relation_name branch November 23, 2023 19:18
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.

2 participants