Questions tagged [yii-relations]
47 questions
1
vote
1 answer
Yii. Application form. Adding info about user company + SEVERAL goods in one form
Don't know, if it is a typical problem, but can't figure how to realise it.
3 tables:
Application. It's relations:
return array(
'company_info' => array(self::HAS_ONE, 'AppCompany', 'applicant_id'),
'region'=>array(
…

Decd
- 65
- 8
1
vote
1 answer
Yii: Accessing attribute from nested joined table of a model
I have a table "MEDICATION" which is joined with "GENERICS_MED_TRADENAMES" table. "GENERICS_MED_TRADENAMES" table contains drug form of medicine which is referred in LIST_OF_VALUES table. After getting the result set of MEDICATION from DataProvider…

FaisalKhan
- 2,406
- 3
- 25
- 32
1
vote
2 answers
Yii joining two table using relations in model
Hi I have these two tables that I want to join using relations in Yii, The problem is Im having a hard time figuring out how Yii relation works.
picturepost
id
title
link_stat_id
linkstat
id
link
post_count
I also have a…

tiltdown
- 451
- 1
- 11
- 26
1
vote
1 answer
relations() in Yii, do not understand the example from the book
I read a book Pactpub Web Application Development with Yii and PHP Nov 2012. Faced with such a problem, I can not understand the logic behind the use of relations (). Here diagram tables in the database:
You need to insert code in the model:
Issue…

SkyStar
- 169
- 1
- 3
- 14
1
vote
2 answers
Changing the condition of relations in Yii
I'm facing a little problem and I need your help. I would like to join two tables, but there would be other conditions for the join not just the foreign key. I have tried setting condition parameter but it creates a WHERE in my query and this will…

psychoo118
- 23
- 1
- 4
1
vote
1 answer
How to sort and search in a CGridView column with a two-level 1-N relation?
This question directly follow this other
I have this tables: Groups, Users, Reports
Relations:
Groups 1 -> N Users ** and ** Users 1 -> N Reports
I already have this relation In Report model:
'user' => array(self::BELONGS_TO, 'Users',…

realtebo
- 23,922
- 37
- 112
- 189
0
votes
1 answer
yii2 How to order via relation by COUNT?
I have a organizers, which do tournaments where a player can participate.
So I have the tables organizer, tournament, participation, player.
I made a relation in the organizer model that gives me all players who ever payer in a tournament organized…

Mathias
- 334
- 3
- 5
- 22
0
votes
1 answer
Yii2: How to declare a has-many relation where either of two attributes match an id?
The model Team has two has-many relations to Game:
public function getGamesWhereTeamIsSetAsHome()
{
return $this->hasMany(Game::className(), ['teamHome' => 'id']);
}
public function getGamesWhereTeamIsSetAsAway()
{
return…

Mathias
- 334
- 3
- 5
- 22
0
votes
1 answer
Complex Filtering of Relations in Yii1
Currently I'm having a problem which I'm not able to solve elegantly.
Given is this (simplified) DB-Design
Each video has many stats. To this point it is a normal 1-n relation, however there are some constraints.
I want to fetch n videos eager…

thpl
- 5,810
- 3
- 29
- 43
0
votes
1 answer
Yii and Relational Queries
I have some tables that have foreign key references:
User -> Tech -> TechSchedule -> Location -> Customer
It seems that I can use the following query once to get any related data to the user. Consider the following query:
// load the user…

visevo
- 791
- 7
- 23
0
votes
1 answer
Yii. How to establish relations and crud between three models (A->B->C)
Can't even imagine how to realize the next feature.
WHAT WE HAVE:
Table 1: application
id - name - //other columns
Table 2: app_company
id - company_name - region_id - applicant_id - //other columns
Table 3: app_region
id - region_name
I've…

Decd
- 65
- 8
0
votes
0 answers
Yii. Object of class AppCompany could not be converted to string on validation
I've been trying to implement this for my AR relations:
http://www.yiiframework.com/wiki/19/how-to-use-a-single-form-to-collect-data-for-two-or-more-models/
And doing:
public function actionCreate()
{
$application = new Application;
$company…

Decd
- 65
- 8
0
votes
1 answer
Yii relation returns null on Linux
I'm facing with a strange problem. I made an application on Windows, and I'm trying to deploy it to Linux. I know about the case problems, and corrected it where I could, but this time I don't know what to do.
I have the following model:
public…

Szigyártó Mihály
- 521
- 6
- 11
0
votes
2 answers
Yii relation Trying to get property of non-object
I've these tables
estudiantes
id_estudiante pk
nombre_estudiante
evaluaciones
id_evaluacion pk
evaluacion_estudiante
evaluacion_asignatura
asignaturas
id_asignatura pk
nombre_asignatura
in evaluaciones model relations
return array(
…

Julioarhernandez
- 167
- 2
- 11
0
votes
0 answers
Relation between tables without primary key
Two tables 1 and 2, where id_schedule in 2 table is not primary key:
Task is to get the dates from table 2. I have the following code:
public function relations()
{
return array(
'scheduleTitles' => array(self::BELONGS_TO,…

Eugene Shmorgun
- 2,083
- 12
- 42
- 67