Closed cabloo closed 9 years ago
That's intentional and totally how hydrate should work. It's specifically to hydrate the data from the db into a model.
Ah, I understood it as turning raw arrays into models so that they could be stored in the database.
So I should just create a second function like hydrate that does this specifically for seeding, using the logic from my overridden hydrate function?
On Mon, Jun 22, 2015, 2:39 AM lukasgeiter notifications@github.com wrote:
That's intentional and totally how hydrate should work. It's specifically to hydrate the data from the db into a model.
— Reply to this email directly or view it on GitHub https://github.com/laravel/framework/issues/9360#issuecomment-114021187.
These sections of the docs should help you:
I think this ticket can be closed. :)
Yes, thanks for your help. It's unfortunate that there's no fillMany
or similar in Eloquent, I ended up renaming the hydrate
function I wrote above to fillMany
for this use case.
I stumbled upon this issue while writing a Seeder. The code should be fairly self-explanatory. When I run this, nothing shows up in the database.
After some digging through the
Model
source code, I found that thehydrate
function ends up creating a newModel
instance and sets theexists
property totrue
. Then, when calling the save function, nothing is added to the database because it is assumed to exist there already.As a temporary fix for my use case, I added this to my base
Model
. With this code added, everything shows up in the database as expected.However, I think the correct solution would be to create each new
Model
instance without assuming it exists already.