Welcome Guest, Not a member yet? Register   Sign In
help in using & improving my_model
#8

[eluser]Lykos22[/eluser]
Hi, I'd like some help please, as I face quite the same difficulty. I'm also using the same MY_Model and I have 3 tables

Code:
**Products**
product_id //eg 1
product_name //eg apple imac
description // mplah mplah
category_id // 3 - desktops
...

**Features**
feature_id // 1
feature_name // processor
category_id // takes the parent-category eg computers with id = 1

and a pivot table **product_features** that should have something like this
product_id // 1
feature_id // 1
feature_value // intel i5

Each table also represents a model, so i have a product_model for products, feature_model for features and a product_feature_model for product_features (which i'm not sure yet if its needed)

In my view I have a form in which i do inserting/editing, in which I want to fetch all the features of the specific category (in my example 'computers') and the values that also belong to the specific product.

Here's the query I've tested in phpmyadmin and also the method
Code:
SELECT `features`.*, `product_features`.`value`
FROM (`features`)
LEFT JOIN `product_features` ON `features`.`feature_id`=`product_features`.`feature_id`
WHERE `category_id` =  '1'  
------------------------------------------------
// this is inside feature_model
public function get_features_values($category_id){
  $this->db->select('features.*, product_features.value')
  ->join('product_features', 'features.feature_id=product_features.feature_id', 'left');
  return parent::get_by('category_id', $category_id);
}
but I also want to specify and which is the product in order to get the correct feature_values.
How can I make this in order to create the method, and in which model should I place my method too??


Messages In This Thread
help in using & improving my_model - by El Forum - 03-23-2012, 01:57 AM
help in using & improving my_model - by El Forum - 03-23-2012, 05:57 AM
help in using & improving my_model - by El Forum - 03-23-2012, 06:18 AM
help in using & improving my_model - by El Forum - 03-25-2012, 01:09 AM
help in using & improving my_model - by El Forum - 03-25-2012, 04:12 AM
help in using & improving my_model - by El Forum - 03-25-2012, 05:10 AM
help in using & improving my_model - by El Forum - 03-25-2012, 06:02 AM
help in using & improving my_model - by El Forum - 09-06-2013, 02:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB