dimanche 1 mai 2016

How to create a new record without executing a database query?

I have Question and Answer models. The Question hasMany Answers. Following commands run in the php artisan tinker mode invoke a database query for no apparent reason:

$q = new Question;
$q->answers[] = new Answer; // invokes the below query

// the executed query
select * from `answers` where `answers`.`question_id` is null and `answers`.`question_id` is not null

As you see, there is no need for database call whatsoever. How can I prevent it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire