yiisoft / active-record

Active Record database abstraction layer
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
68 stars 28 forks source link

Rename `$attributes` to `$properties` #343

Closed Tigrov closed 2 weeks ago

Tigrov commented 4 months ago

@xepozz What's the reason to rename attributes to properties?

It was discussed that there is confusion between the $attributes AR property and PHP's #[Attribute].

But it's a good question. Now this looks doubtful due to major changes and needs to be discussed again. Due to the renaming of public methods whose names contain attribute.

@vjik Are there any pitfalls here? Rename methods also it looks logically.

Now property name is already used in other methods

https://github.com/yiisoft/active-record/blob/090db08a3bb6833e0149bd9efd5aa521195270f7/src/BaseActiveRecordTrait.php#L275-L307

Currently attributes means column names in a table. properties means properties of a class, wouldn't properties cause confusion similar to attributes.

fields is a more appropriate name, but it is also used for ArrayableInterface:

https://github.com/yiisoft/active-record/blob/090db08a3bb6833e0149bd9efd5aa521195270f7/src/BaseActiveRecord.php#L93-L108

If major changes involving method renaming are not a problem, then they should be separated into names and values:

And we should avoid set and get prefixes when declaring method names in base AR classes. These prefixes will be used to access values of a row e.g. getName(), setName()

vjik commented 4 months ago

Should there be a difference between class property values and column values from the user's point of view? Isn't that the same thing?

Tigrov commented 4 months ago

There is some chaos in this:

Column names and values can be accessed as class properties. But properties are not limited to column names. The class can contain any other properties. And if renaming getAttributes() to getProperties() the method will not return all class properties but only properties associated with column names.

We wanted to change the name to avoid confusion, but other confusion may arise.

vjik commented 4 months ago

So, there are:

right?

We can clearly name methods: getColumnNames(), getColumnValues(), getProperties(), ...

Tigrov commented 4 months ago

(column values + aggregate and other values) stored in one place in $attributes property. getAttributes(), getAttribute(), setAttribute() methods interact with $attributes property.

In addition, the user can define any other properties of the class.

What about a suggestion from the first message?

previous name -> new name

and rename property $attributes to $values or $data according to the method name to get values of a row