Closed thepurpleblob closed 8 years ago
Just released you can add a select (..) in there to override the default but it's not clear from the documentation. The join documentation is a bit sparse.
Alias the fields as you would in straight SQL. This isn't the concern of the ORM, but a direct result of the query that you're running as it comes back via SQL and PHP - fields of the same name? Last one wins. On 14 Dec 2015 08:34, "Howard Miller" notifications@github.com wrote:
If two tables (as is likely) each have an id field then the join seems to return the value of the "joined" table. It seems logical to me that it would return the id field from the table specified in forTable(). This may be intentional but it isn't clear in the documentation. This is at odds with what happens if I construct the SQL query by hand.
$pricebands = \ORM::forTable('Priceband')->join('Destination', array('Priceband.destinationid', '=', 'Destination.id'))->where('pricebandgroupid', $id)->findMany();
(Priceband and Destination tables both have 'id' fields)
...this returns data containing the id field from the Destination table.
select * from priceband left join destination on (priceband.destinationid = destination.id) where pricebandgroupid=52;
(which is what I would expect this constructs) returns the id fields from the Priceband table.
— Reply to this email directly or view it on GitHub https://github.com/j4mie/idiorm/issues/285.
You can issue a pull request against the documentation - look forward to seeing your improvements. On 14 Dec 2015 08:43, "Howard Miller" notifications@github.com wrote:
Just released you can add a select (..) in there to override the default but it's not clear from the documentation. The join documentation is a bit sparse.
— Reply to this email directly or view it on GitHub https://github.com/j4mie/idiorm/issues/285#issuecomment-164307245.
If two tables (as is likely) each have an id field then the join seems to return the value of the "joined" table. It seems logical to me that it would return the id field from the table specified in forTable(). This may be intentional but it isn't clear in the documentation. This is at odds with what happens if I construct the SQL query by hand.
$pricebands = \ORM::forTable('Priceband')->join('Destination', array('Priceband.destinationid', '=', 'Destination.id'))->where('pricebandgroupid', $id)->findMany();
(Priceband and Destination tables both have 'id' fields)
...this returns data containing the id field from the Destination table.
select * from priceband join destination on (priceband.destinationid = destination.id) where pricebandgroupid=52;
(which is what I would expect this constructs) returns the id fields from the Priceband table.