Hi guys,
I am having a problem with a relationship between 3 models. (Products, ProductStock, PriceRules). I am showing Products and ProductStock has the current stock level, while PriceRules has the special price available for a product (if any). Products have a hasMany relationship with the other two models and the other models have a belongsTo relationship with Products.
Here are the relationships:
Products:
$this->hasMany('id', __NAMESPACE__ . '\PriceRules', 'product_id', array(
'alias' => 'PriceRules',
'foreignKey' => array(
'action' => Relation::ACTION_CASCADE
)
));
$this->hasOne('id', __NAMESPACE__ . '\ProductStock', 'product_id', array(
'alias' => 'ProductStock',
'foreignKey' => array(
'action' => Relation::ACTION_CASCADE
)
));
ProductStock & PriceRules both look like this:
$this->belongsTo('product_id', _NAMESPACE_ . '\Products', 'id', array(
'alias' => 'Products'
));
Now, in the view (using Volt), I al doing something like this:
{% for product in products %}
{{ product.ProductStock.stock }}
{{ product.PriceRules.price }}
{% endfor %}
While product.ProductStock.stock
correctly displays the stock level, product.PriceRules.price
comes up null.
I am logging all SQL queries and I can veryfy that the queries return the correct result for PriceRules. I can also verify this but dumping product.PriceRules
, which contains the value I want.
Can anyone think of any reason PriceRules does not display the value?