Hello,
Lets say I have 3 models Cars, CarsBrands and Brands.
Cars Model:
<?php
use Phalcon\Mvc\Model;
class Cars extends Model
{
public $id;
public $name;
public $visits;
public function initialize()
{
$this->hasMany('id', 'CarsBrands', 'car_id', ['alias' => 'cars_brands']);
}
}
CarsBrands Model:
<?php
use Phalcon\Mvc\Model;
class CarsBrands extends Model
{
public $id;
public $brand_id;
public $car_id;
public function initialize()
{
$this->belongsTo('car_id', 'Cars', 'id');
$this->belongsTo('brand_id', 'Brands', 'id');
}
}
And brand model is not even importnat here.. It will have id and brand name ..
I need two querys.
I need to make query that will pull 10 cars from database ordered by visits number (visits is field n Cars), where brand id is not 5 (witouth cars with brand id 5).
Second query is, to pull 10 cars ordered by visits where brand id is 4.