You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 of SELECT *
To illustrate another way:
Table 1 - User has one record:
id
name
1
joel
Table 2 - Account has one record:
id
name
details
1
mad max
null
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:
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.
The text was updated successfully, but these errors were encountered: