Skip to content

Commit

Permalink
[doc] Added another relation example to Many-To-One (#93)
Browse files Browse the repository at this point in the history
This is documented in Many-To-Many already, but not here.
  • Loading branch information
weaverryan authored Dec 7, 2020
1 parent 2d574a5 commit e4d0a06
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,13 @@ PostFactory::new()->many(5)->create(); // create 5 Posts

CommentFactory::new()->create(['post' => PostFactory::random()]);

// or create many, each with a different random Post
CommentFactory::new()->many(5) // create 5 comments
->create(function() { // note the callback - this ensures that each of the 5 comments has a different Post
return ['post' => PostFactory::random()]; // each comment set to a random Post from those already in the database
})
;

// Example 3: create a separate Post for each Comment
CommentFactory::new()->many(5)->create([
// this attribute is an instance of PostFactory that is created separately for each Comment created
Expand Down

0 comments on commit e4d0a06

Please sign in to comment.