This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// So I'm going to be demonstrating a problem with INNER joins | |
//Bake automatically creates INNER JOINs for a belongsTo association, | |
// where the foreign key is not allowed to be null (Always BelongsTo) | |
// This is great if you have an (AlwaysBelongsTo) association, but | |
// when you don't always BelongTo another model, we need LEFT joins. | |
// The problem arised when you have a model that someTimesBelongsTo another model | |
// and that other model alwaysBelongsTo another model (LEFT, then INNER joins) | |
// Cake doesn't use proper parenthesis in these cases, but simply lines the joins up, | |
// one after another. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Test\Fixture; | |
use Cake\TestSuite\Fixture\TestFixture; | |
/** | |
* ReservationsFixture | |
* | |
*/ | |
class ReservationsFixture extends TestFixture |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App\Model\Entity\Product::_getStockApiUniqueCode() - APP/Model/Entity/Product.php, line 109 | |
Cake\ORM\Entity::get() - CORE/src/Datasource/EntityTrait.php, line 294 | |
Cake\ORM\Entity::has() - CORE/src/Datasource/EntityTrait.php, line 340 | |
Cake\ORM\Entity::offsetExists() - CORE/src/Datasource/EntityTrait.php, line 473 | |
App\Model\Table\ProductsTable::beforeSave() - APP/Model/Table/ProductsTable.php, line 138 | |
Cake\Event\EventManager::_callListener() - CORE/src/Event/EventManager.php, line 390 | |
Cake\Event\EventManager::dispatch() - CORE/src/Event/EventManager.php, line 356 | |
Cake\ORM\Table::dispatchEvent() - CORE/src/Event/EventDispatcherTrait.php, line 78 | |
Cake\ORM\Table::_processSave() - CORE/src/ORM/Table.php, line 1439 | |
Cake\ORM\Table::Cake\ORM\{closure}() - CORE/src/ORM/Table.php, line 1391 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// In my model | |
$package = $this->get($options['package_id']); | |
$products = $this->Products->find() | |
->where(['Products.package_id' => $options['package_id']]) | |
->toArray(); | |
$this->Products->unlink($package, $products); | |
// This is giving me an error: | |
// InvalidArgumentException |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// In my controller: | |
$delivery = $this->Deliveries->get($id, [ | |
'contain' => ['Warehouses', 'DeliveryNotes', 'Orders', 'Products' => function ($q) { | |
return $q->find('filtered', ['options' => ['group' => 'ean']]) | |
->select(['Products.id', 'ProductInfo.sku', 'ProductInfo.id', 'Products.size', 'Products.product_info_id']) | |
->contain('ProductInfo'); | |
}] | |
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
Products.id AS `Products__id` | |
FROM | |
products Products | |
INNER JOIN websites Websites ON Websites.id = 1 | |
INNER JOIN products_websites ProductsWebsites ON ( | |
Products.id = (ProductsWebsites.product_id) | |
AND Websites.id = (ProductsWebsites.website_id) | |
) | |
INNER JOIN product_info ProductInfo ON ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$allowedIds = $this->Websites->Products->find() | |
->extract(['id']) | |
->where(['reservation_id IS' => null]) // Product is not already reserved | |
->where(['size' => $converter->convert($request['size_eu'], $gender['gender'])]) // Product size matches | |
->where(['id IN' => TableRegistry::get('ProductsWebsites')->find() // Product belongs to the Website | |
->select(['product_id']) | |
->where(['website_id' => $website->id]) | |
]) | |
->where(['product_info_id IN' => $this->Websites->Products->ProductInfo->find() // Product sku matches | |
->select('id') |
NewerOlder