Questions tagged [yii-relations]
47 questions
0
votes
1 answer
yii relations trough one table
is it possible in Yii 1.1.14 to connect these tables using one "object_rel" table?
object_rel:
id
owner_id (e.g. location record id)
owner_type (e.g. 2 = location)
slave_id (e.g. program record id)
slave_type (e.g. 1 = program)
location(type =…

reetah
- 221
- 3
- 2
0
votes
1 answer
Yii relation through
I have 3 tables:
House:
id
name
...
Activity:
id
Title
...
Category:
id
title
...
I want to make a relation like $category->houses to return all house which have an activity in the specifique category.
I tried something like:
public function…

user2869049
- 129
- 1
- 9
0
votes
2 answers
Yii relations on non primary and non foreign key fields
I am having trouble creating relations on non-key fields. My issue is that all records from the 'HAS_MANY' table are being returned, rather than just the matching values specified in the 'on' section of the relation.
Table: customer
- id (PK)
-…

Charles Brown
- 25
- 1
- 3
0
votes
1 answer
Yii condition relations issue
Im having trouble with Yii conditions.
My code:
$criteria=new CDbCriteria;
//$criteria->together = true;
$criteria->group='t.id';
$criteria->with = array('farmer_goods','goods_catalog');
//$criteria->compare('farmer_goods.price',…

Ga1der
- 171
- 1
- 5
0
votes
1 answer
Yii - CGridView activerecord relation
I need to print out the result in CActiveDataProvider with CGridView and with pagination
The following is my function in model
public function getCompaniesJobsByCompanyId ( $companyId )
{
$criteria = new CDbCriteria(array(
…

user1476552
- 107
- 1
- 1
- 11
0
votes
1 answer
Hackneyed subject search MANY_MANY in YII , but everywhere a lot of info, all different, help me to understand
I have tables
1) tours (id, title)
2) categories (id, title)
3) tours_categories (tour_id, category_id)
Model Tours:
public function relations ()
{
return array (
'Category' => array (self :: MANY_MANY,
…

Stiloff
- 13
- 5
0
votes
1 answer
How to fitch the result from Yii active recorde query with relations and scopes
This is my code
$vacanciesObjects = Vacancies::model()->status('approved')->visibility('Visible')->removed(0)->archived(0)->findAll(
array(
'with'=>array(
'job'=>array(
//'select' => 'title',
'scopes'=>array(
…

user1476552
- 107
- 1
- 1
- 11
0
votes
2 answers
How To Build Relations To Display Columns Of 4 Tables In Cgridview
I have a requirement where I need to build the relations between more than 3 tables.
I have 4 tables namely, Message, Flat, Person, Mapping tables.
Now, below tables have the following fields:
Message:
`Id`…

Rudra
- 711
- 7
- 13
- 31
0
votes
1 answer
Join a model with itself in Yii causes non-object error
I have a model with these fields :
id , name , parent_id
I store a hirechical structure in this table.
somw example records are:
1 - fruits - 0
2 - foods - 0
3 - colors - 0
4 - apple - 1
5 - red - 3
6 - meat- 2
In the gridview of…

hd.
- 17,596
- 46
- 115
- 165
0
votes
1 answer
How to get more data from a relationship table in Yii
I have 3 tables:
numbers (id, name)
food (id, name)
numbers_food (number_id, food_id, price_per_ad, price_per_ch)
How I can to get a price_per_ad and price_per_ch data for each food_id from numbers_food relationship table?

Footniko
- 2,682
- 2
- 27
- 36
0
votes
2 answers
Yii how to count related models (getRelation with params)?
I have a HAS_MANY relation called "relationName",
So I can get all related models using
$model->relationName;
or using
$model->getRelated('relationName');
I can also get a subset of relatedModels, by adding…

Max Zhuravlev
- 324
- 3
- 13
0
votes
0 answers
How can I have a conditional relationship in a model?
I have two types of profiles in the application, and they are two different tables. For example, personal profiles are in the 'person' table and their IDs begin with 'p', and the business profiles are in the 'business' table and their IDs begin with…

Parham Doustdar
- 2,019
- 3
- 22
- 41
0
votes
1 answer
Yii relations result non-existing items (cache issue?)
I have set relations: 'teamDrivers' => array(self::HAS_MANY, 'TeamDriver', 'team_id') in my Team model
So if I want I can: print_r($this->teamDrivers); in my Team. Just for demonstration.
Now the problem is that this kind of code produces a list of…

Gessle
- 255
- 1
- 3
- 10
0
votes
1 answer
Build a specific relation of models YII activerecord
I'm trying to display Vehicle model using CGridView.
In order to display value of Fld7465RRef reference column, following sql select is needed:
select VUF._Fld7468_S as Loading_Time_To_DLR
FROM Vehicles as Vehicles
left join (_InfoReg7464 as…

user1968944
- 21
- 2
0
votes
1 answer
Recursive Yii queries
I'm fairly new to Yii and have run into a barrier with related models. I suspect other beginners also run into this from time to time and would be grateful for any input even if just to point me in the right direction as I can't find anything on…

goose
- 2,502
- 6
- 42
- 69