Welcome Guest, Not a member yet? Register   Sign In
Best way for two models in one controller?
#1

Hi everyone,
My question is about following: I have two tables, products and products_description. First holds the general information like price and article number of the products, the description the textual description for each language, so 1:n (like 1 product can have many descriptions in different languages).
So I have controller "Products" and two models for each table.
When I like to query ALL product info in one call.... like general information plus description and details, what do I do best?
Reply
#2

Example. Or create new class ProductManager with new methods.
PHP Code:
$products model(ProductsModel::class)->withDescription() 
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#3

I am probably not experienced enough for this, but how do I define withDescription? Is it a model function that includes the products_description model?
Reply
#4

PHP Code:
class ProductModel extends Model
{
    public function withDescription() {
        return $this->join('products_description''products.id = products_description.product_id''LEFT')
            ->where('products.id'1);
    }


Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#5

ok so I wasn't wrong with this. Thank you!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB