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

Why is hasOne and hasMany array key/value order opposite? #14313

Closed
davidjeddy opened this Issue Jun 19, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@davidjeddy
Contributor

davidjeddy commented Jun 19, 2017

What steps will reproduce the problem?

n/a

What is the expected result?

k/v order to be similar

What do you get instead?

k/v order is opposite when comparing hasOne Vs hasMamany

Additional info

Q A
Yii version 2.0.10
PHP version 7.0+
Operating system Linux
hasOne()
* 
* public function getCountry()
* {
*     return $this->hasOne(Country::className(), ['id' => 'country_id']);
* }
*

hasMany()

*
* public function getOrders()
* {
* return $this->hasMany(Order::className(), ['customer_id' =>; 'id']);
* }
*
Notice the opposite order?
@bizley

This comment has been minimized.

Show comment
Hide comment
@bizley

bizley Jun 19, 2017

Contributor

This is intended. From the Guide:

An easy rule to remember this is, as you see in the example above, you write the column that belongs to the related Active Record directly next to it. You see there that customer_id is a property of Order and id is a property of Customer.

This actually makes it easier to remember.

Contributor

bizley commented Jun 19, 2017

This is intended. From the Guide:

An easy rule to remember this is, as you see in the example above, you write the column that belongs to the related Active Record directly next to it. You see there that customer_id is a property of Order and id is a property of Customer.

This actually makes it easier to remember.

@jlorente

This comment has been minimized.

Show comment
Hide comment
@jlorente

jlorente Jun 19, 2017

Contributor

This isn't an Issue and maybe you should use the forums to ask this kind of things. But answering your question, the value of the array is the property of the model where you are declaring these methods and the key of the array is the property of the related model.

Contributor

jlorente commented Jun 19, 2017

This isn't an Issue and maybe you should use the forums to ask this kind of things. But answering your question, the value of the array is the property of the model where you are declaring these methods and the key of the array is the property of the related model.

@davidjeddy

This comment has been minimized.

Show comment
Hide comment
@davidjeddy

davidjeddy Jun 20, 2017

Contributor

I was expecting a systematic approach similar to [ThisAR->property => OtherAt->property]. But I get the reasoning behind the current implementation.

Contributor

davidjeddy commented Jun 20, 2017

I was expecting a systematic approach similar to [ThisAR->property => OtherAt->property]. But I get the reasoning behind the current implementation.

@davidjeddy davidjeddy closed this Jun 20, 2017

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