Skip to content

Instantly share code, notes, and snippets.

@asaokamei
Created April 19, 2014 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asaokamei/11076579 to your computer and use it in GitHub Desktop.
Save asaokamei/11076579 to your computer and use it in GitHub Desktop.
Eloquentのモデル生成法比較:newとcreate ref: http://qiita.com/asaokamei/items/bdad9d0f931f0840a3a9
$entity1 = new Model();
$entity2 = Model::create( array() );
class Blog extends Eloquent {
public comments() {
return $this->hasMany('Comment');
}
}
class Comment extends Eloquent {
public blogs() {
return $this->BelongsTo('Blog');
}
}
$blog = new Blog();
$comment = new Comment();
$blog->comment()->save($comment); // 例外発生!
$blog = Blog::create(array());
$comment = Comment::create(array());
$blog->comment()->save($comment); // 問題なし!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment