I have three tables - products, features and product_feature - as
products
- id
- name
features
- id
- key
product_feature
- product_id
- feature_id
- value
I was retrieve all (key, value) pairs for a product. The SQL statement is
SELECT key, value FROM products
JOIN product_feature pf
ON pf.product_id = "Product ID"
JOIN features f
ON f.id = pf.feature_id
How do I established that relationship
// Inside Product model
function features() {
// Has many through relationship
}