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

SQL column alias bug #51

Closed
michalbundyra opened this issue Jan 16, 2020 · 4 comments
Closed

SQL column alias bug #51

michalbundyra opened this issue Jan 16, 2020 · 4 comments

Comments

@michalbundyra
Copy link
Member

....$select...->join('vendors', 'vendors.id = campaigns_vendors.vendor_id', ['vendor_id'=>'id', 'vendor_daily_limit'=>'daily_limit'], $select::JOIN_LEFT)

When I query this select object I get the following error: "Not a valid magic property for this object"
When I rename the column alias to anything else but 'vendor_daily_limit' the error goes away.
When I print the produced SQL and run it via phpMyadmin or Bench then the query executes perfectly.

Very bizarre error and no indication of what is causing it.


Originally posted by @TradeSharer at zendframework/zend-db#317

@michalbundyra
Copy link
Member Author

I have no luck to reproduce that error on my local env)

Could you please add more information, may be table structure or scope code ?)


Originally posted by @tptrixtop at zendframework/zend-db#317 (comment)

@michalbundyra
Copy link
Member Author

you should can do something like this:

use Zend\Db\Sql\Predicate\Expression;

$select->join(
     'vendors', 
     'vendors.id = campaigns_vendors.vendor_id', 
     [
         'vendor_id'          => new Expression('vendors.id'),
         'vendor_daily_limit' => new Expression('vendors.daily_limit'),
      ],
      $select::JOIN_LEFT
);

Originally posted by @samsonasik at zendframework/zend-db#317 (comment)

@michalbundyra
Copy link
Member Author

It turns out I was looking at the wrong code.
The error "Not a valid magic property for this object" is produced when you call a non-existing method on the Sql object i.e. $sql->join(....)->equalTo(....) - equalTo is a method of Where and not Sql, since ZF uses overloading for this, the error message is not obvious.
A better message would be something like: "method equalTo not defined for Sql"

Sorry for wasting your time.


Originally posted by @TradeSharer at zendframework/zend-db#317 (comment)

@weierophinney
Copy link
Member

This package is considered feature-complete, and is now in security-only maintenance mode, following a decision by the Technical Steering Committee.
If you have a security issue, please follow our security reporting guidelines.
If you wish to take on the role of maintainer, please nominate yourself

If you are looking for an actively maintained package alternative, we recommend:

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

No branches or pull requests

2 participants