[DC-601] When using a join and giving an alias to each select column the hyrdrator only returns one row. Created: 25/Mar/10 Updated: 02/Aug/10 |
|
| Status: | Open |
| Project: | Doctrine 1 |
| Component/s: | Query, Relations |
| Affects Version/s: | 1.2.2 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | will ferrer | Assignee: | Guilherme Blanco |
| Resolution: | Unresolved | Votes: | 2 |
| Labels: | None | ||
| Environment: |
XP Xamp |
||
| Description |
|
Hi All $q = Doctrine_Query::create(); Generates this DQL:
SELECT Customer.firstname as first_name, Customer.postalcode as postalcode FROM Customer Customer LEFT JOIN Customer.Zip Zip And this SQL:
SELECT c.firstname AS c_0, c.postalcode AS c_1 FROM customers c LEFT JOIN zips z ON c.postalcode = z.postalcode Which results in this return after hyrdration: array('0'=>array('first_name'=>'Armando', 'postalcode'=>'00659')) However the following code hydrates just fine: $q = Doctrine_Query::create(); As does this code:
$q = Doctrine_Query::create();
Here is the yaml for the sample data I am testing on:
detect_relations: false Perhaps there is something simple I am overlooking. To get around this I am just always selecting the primary key from my main table in every query. Thanks in advance for any advice. |
| Comments |
| Comment by will ferrer [ 03/Apr/10 ] |
|
This problem also exists in 1.2.2 so I have updated the post to reflect this. |
| Comment by Peter Bücker [ 06/Apr/10 ] |
|
I experienced the same problem with Doctrine 1.2 (r7329). I also fixed this by adding the primary key of the table I select from to the select list. |
| Comment by will ferrer [ 07/Apr/10 ] |
|
Hi Peter Thats how I am currently working around the bug as well but hopefully it will get rectified in a later version of doctrine. Thanks for the comment. Will |
| Comment by Sam Doun [ 08/Jun/10 ] |
|
Hi all, I'm new to doctrine and since yesterday, I'm experiencing exactly the same behavior. Regards, |
| Comment by will ferrer [ 08/Jun/10 ] |
|
Hi Sam Currently I am working around this bug by always adding the primary key of the table to the select (like peter also mentions above). It is a work around for the problem but so far it has been reliable for me. I hope that helps until there is a patch for it. Will Ferrer |
| Comment by Sam Doun [ 09/Jun/10 ] |
|
Hi Will I'll do so. Sam Doun |
| Comment by Shuchi Sethi [ 02/Aug/10 ] |
|
Hi, Has there been any patch release for the same? For DQL - function getServiceDetails($merchantId,$merchantServiceId) {
$q = Doctrine_Query::create()
->select('b.*, m.name as merchant_service_name,payment_mode.name as payment_mode_name,payment_mode.id as paymentMode,p.id as paymentModeOption ')
->from('ServicePaymentModeOption b')
->leftJoin("b.MerchantService m")
->leftJoin("m.Merchant merchant")
->leftJoin("b.PaymentModeOption p")
->leftJoin("p.PaymentMode payment_mode")
->where("merchant.id=?",$merchantId)
->andWhere("b.merchant_service_id=?",$merchantServiceId)
->groupBy('p.name');
return $res = $q->execute(array(),Doctrine::HYDRATE_ARRAY);
}
Result with Doctrine 1.1 is Array
(
[0] => Array
(
[id] => 1
[merchant_service_id] => 1
[payment_mode_option_id] => 1
[created_at] =>
[updated_at] =>
[deleted] =>
[created_by] =>
[updated_by] =>
[merchant_service_name] => NIS Passport
[merchant_name] => NIS
[payment_mode_option_name] => Bank
[payment_mode_name] => Bank
[paymentMode] => 1
[paymentModeOption] => 1
[MerchantService] => Array
(
[merchant_service_name] => NIS Passport
[Merchant] => Array
(
[merchant_name] => NIS
)
)
[PaymentModeOption] => Array
(
[payment_mode_option_name] => Bank
[paymentModeOption] => 1
[PaymentMode] => Array
(
[payment_mode_name] => Bank
[paymentMode] => 1
)
)
)
)
Result with Doctrine 1.2 is Array
(
[0] => Array
(
[id] => 1
[merchant_service_id] => 1
[payment_mode_option_id] => 1
[created_at] =>
[updated_at] =>
[deleted_at] =>
[created_by] =>
[updated_by] =>
[merchant_service_name] => NIS Passport
[merchant_name] => NIS
[payment_mode_option_name] => Bank
[payment_mode_name] => Bank
[paymentMode] => 1
[paymentModeOption] => 1
)
)
We have used Hydration for the result set at lot of places. Please suggest if there could be a fix without going about revising everything that has been coded. Looking forward to a quick response. |