Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Default Relation Model Instnces

$
0
0
Hello,

Is there any *nice* way to achieve something like this?:

I have a model Work, Work has 2 HAS_MANY relations and 1 HAS_ONE relation:
- (many)Incomes
- (many)Tasks
- (one) Assignee

now when I am building a form for a new Work model, I have to do all the needed logic in the model controller create action, example:

 $model = new Work;
 $incomes = array(new Income);
 $tasks = array(new Task);
 $assignee = new User

 $this->render('form_fom_creating_new_work_record', array(/*all the models I created*/));


The thing I am thinking of, is invoking *some magic* for example in afterConstruct() method, to create those needed models and attach them to relations of Work, so that I don't have to remember, to do it everywhere in the code elswhere I will use new Work;

Did you practice that, do you thinks it's very wrong or rather usefull for you too?

cheers.F

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>