G
G
GM2mars2014-02-06 23:25:29
Yii
GM2mars, 2014-02-06 23:25:29

Is it possible to create one model for two tables in Yii?

When adding an article to the database, you have to write it to two tables: the main one - articles and the additional one - tags. Is it possible in Yii to create a model based on two tables and it is convenient to work with this model through the controller?

tables
articles
1. id
2. title
3. text
4. autor
tags
1. id
2. name
3. id_articles

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Zelenin, 2014-02-06
@GM2mars

the answer is no, but here is what you need:
yiiframework.ru/doc/cookbook/ru/model.save.related.data
habrahabr.ru/post/118910
habrahabr.ru/post/200478

A
AndB31, 2014-02-08
@AndB31

Generally speaking, it is possible, although perverted:

public function tableName() {
    $tableNum = (isset($_REQUEST['bookindex'])) ? (int)$_REQUEST['bookindex'] : 1;
    return 'gbook'.$tableNum.'_messages';
  }

The model works with tables
'gbook1_messages', 'gbook2_messages'... and so on.
The structure of the tables is, of course, the same.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question