Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

CakePHP 3.x - InvalidArgumentException to relate entities #813

Closed
edsonmgoz opened this issue Jan 24, 2016 · 4 comments
Closed

CakePHP 3.x - InvalidArgumentException to relate entities #813

edsonmgoz opened this issue Jan 24, 2016 · 4 comments

Comments

@edsonmgoz
Copy link

When I try to relate two entities, faker is not executed correctly and that generates a InvalidArgumentException:

[InvalidArgumentException]

randomNumber() can only generate numbers up to mt_getrandmax()

As a result it does not generate the data in the related table let alone the FK. Clarify that I'm not using the method randomNumber() anywhere in my code. I'm working with CakePHP 3.1.7

Please appreciate it if you could check that detail.

Thank you very much for all your great work!

@fzaninotto
Copy link
Owner

I don't use CakePHP, can any of the contributors of this part take a look? ping @jadb @daniel-mueller @pomaxa @davidyell

@davidyell
Copy link
Contributor

As a reference, cakephp/bake#162

If you're using Phinx > 0.5.0 you can now use that for your database seeding, which is part of cakephp/migrations.

Using Faker, I used the $faker->numberBetween(1, 4), for some fields, which might give you more reliable results. Although it sounds like you're generating a pretty large dataset.

You might get some more insight from https://github.com/gourmet/faker

When it comes to the entity generation, you'll want to generate your entities in a loop calling the faker methods to populate the entity properties. You should be able to generate the entities as properties of the entity ($entity->tags is an array of Tag entities) and save it all in one go for things which are directly related.

@davidyell
Copy link
Contributor

I've also just found a random Gist with a pre-configured migration which might prove helpful as a reference.

https://gist.github.com/davidyell/e784e70eb06903a790de

@edsonmgoz
Copy link
Author

Thank you very much @davidyell !!!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants