Sometimes, you'll find it useful to create a new association on the fly before a
find operation to retrieve specific data or filter unwanted result rows from your query.
In this recipe, we'll look at how associations can be defined at runtime on your models.
We'll assume you have the
Warehouse models in place from our previous recipes, where
We'll also add an
active field to our
warehouses tables with the following SQL statement:
ALTER TABLE packages ADD active TINYINT(1) NOT NULL DEFAULT '1'; ALTER TABLE warehouses ADD active TINYINT(1) NOT NULL DEFAULT '1';
We want to retrieve only the stocks with a positive amount for both ...