Open enigmatix opened 7 years ago
And specific case:
join with 2 tables both have dynamic column with the same name
$this->select[$this->_dynamicColumn] =
'COLUMN_JSON(' . $db->quoteColumnName($alias . '.' . $this->_dynamicColumn) . ')';
Hi,
I came across this issue when integrating DynamicActiveRecord into my project. I use scopes to restrict data access for the current user, and these scopes LEFT JOIN a secondary table to ensure that access is permitted.
Unfortunately, if this second table shares column names with the first (eg. id, name), it is these values from the second table that get assigned to the returned model.
The native Yii2 ActiveQuery class handles this by using
SELECT tableAlias.*
instead ofSELECT *
To illustrate another way:
Table 1 - User has one record:
Table 2 - Account has one record:
Example:
$user = User::findOne(1); echo $user->name; // prints 'mad max', should print 'joel'
The fix would ideally be completed at line 110 in DynamicActiveQuery like so:
And by copying the getTableNameAndAlias from the native implementation in ActiveQuery
If you accept the above and it sounds agreeable, I am happy to prepare a pull request for it.