Yii Framework Forum: Grid With Join - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Grid With Join the best way to do that

#1 User is offline   gimox 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 17-July 12
  • Location:ITALY, cagliari

Posted 26 October 2013 - 04:46 PM

my question is, where is the best way to build a grid with a data join from two table?

Now. I do this.


i create the crud with gii.
i perform the query with join by sql


this is my search model

public function search($params)
{
//$query = AgenzieIndirizzo::find();

$sql = 'SELECT * FROM agenzie_indirizzo LEFT JOIN agenzie_main ON agenzie_indirizzo.id_agenzia = agenzie_main.id';
$query = AgenzieIndirizzo::findBySql($sql);

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}

$this->addCondition($query, 'agenzie_main.name');
$this->addCondition($query, 'id');
$this->addCondition($query, 'id_agenzia');
$this->addCondition($query, 'nome', true);
$this->addCondition($query, 'tipo_ind');
$this->addCondition($query, 'citta', true);
$this->addCondition($query, 'provincia', true);
$this->addCondition($query, 'tipo_via');
$this->addCondition($query, 'via', true);
$this->addCondition($query, 'numero_civ', true);
$this->addCondition($query, 'cap', true);
$this->addCondition($query, 'user_ins');
$this->addCondition($query, 'data_ins');
$this->addCondition($query, 'user_mod');
$this->addCondition($query, 'data_mod');
$this->addCondition($query, 'name');
return $dataProvider;
}


after i declare the filed as var in the main model.

i think this work but is not the right method.

( how display in the grid a field if two table has same name filed ex. 'id' .. i try db.it .. and other)

anyone can help me?
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,552
  • Joined: 17-January 09
  • Location:Russia

Posted 27 October 2013 - 01:48 AM

SQL View?
0

#3 User is offline   gimox 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 17-July 12
  • Location:ITALY, cagliari

Posted 27 October 2013 - 05:58 AM

??I don't understand your question
0

#4 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,552
  • Joined: 17-January 09
  • Location:Russia

Posted 27 October 2013 - 07:41 AM

SQL View
0

#5 User is offline   gimox 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 17-July 12
  • Location:ITALY, cagliari

Posted 27 October 2013 - 01:30 PM

View Postsamdark, on 27 October 2013 - 01:48 AM, said:

SQL View?




Sql View is not a real solution.

It consume a large amount of cpu and Ram with big data table, it can be done only with small data.
This is not a right best practice.

If anyone has a opinion about using big table data with view..........
0

#6 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,552
  • Joined: 17-January 09
  • Location:Russia

Posted 28 October 2013 - 08:41 AM

Why? It's supported by most of RDBMs and consumes nearly the same amount of memory as it is consumed for joins.
0

#7 User is offline   gimox 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 17-July 12
  • Location:ITALY, cagliari

Posted 28 October 2013 - 10:34 AM

i think is not the best solution for an oner reason, is not comfortable.

the project i'm working use SQL VIEW and this is not a problem for me now.
i found an good solution to use it in the crud.

When i can test Some db query i send you some benchmark with view and without.

(so a SQL VIEW is same as JOIN but Mysql use more ram using it, i don't now what's mysql do to do that, i hope you right so this can resolve many problem....).
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users