I have built kind of "fat" model of an SMS. I have written a method addRecipient()
which creates new object of related model:
class Smses extends ModelBase {
public function addRecipient($name, $number) {
$recipient = new Recipients();
$recipient->setName($name);
$recipient->setNumber($number);
//is using _related array safe?
$this->_related['recipients'][] = $recipient;
}
public function initialize() {
$this->hasMany("id","Recipients","message_id");
}
}
In my controller I use it this way:
$sms = new Smses();
$sms->addRecipient('Marie','+49779988333');
$sms->addRecipient('Tomas','+49888777666');
$sms->create();
-
Is this solution save? Is here the risk of some inconsistency?
- Does anyone know better solution for this, or have the same problem? How you solved it?