thephpleague / factory-muffin

Enables the rapid creation of objects for testing
https://factory-muffin.thephpleague.com/
MIT License
531 stars 72 forks source link

Issue with unique fields and relations in Factory Muffin #321

Closed frankmichel closed 10 years ago

frankmichel commented 10 years ago

Let's say we have three models, a User, a Products and an Order model. All of these models are related to the Account model in the definitions like so:

'account_id' => 'factory|Account'

Let's assume, the account model has a unique field "hash". Let's say, products and orders have also a defined relation.

The problem: If I create an order with multiple products I will run into an issue with the unique key on the account model. Since the same account model will be created into the database and applied to all of the products and the order.

Is there a way to work around this issue?

frankmichel commented 10 years ago

I guess I just missed the unique paramter... In order to simulate a php uniqid() this does the trick:

'unique:bothify|?##?##?###??#'

scottrobertson commented 10 years ago

Glad you sorted it :)

GrahamCampbell commented 9 years ago

This is much improved in 3.0.