Comments (6)
@webvimark , thanks!
handling automatically DateTime by FakerWrapper would be great
Noted. I plan to add it during this month.
from db-seeder.
Well, this is a faker behavior and is expected. Faker's dateTime provider returns a php DateTime object, which cannot be converted to a string directly. And something like $faker->dateTime->format('r') won't work in FakerWrapper, which is a $faker
in your example for technical reasons atm.
Things you could do ATM:
- Use datetime provider that returns string. See https://github.com/fzaninotto/Faker#fakerproviderdatetime , it has date and time providers.
- Make your own anonymous function provider, i.e.
function() {
return date('Y-m-d H:i:s', rand(0, time());
}
Anyway, you have raised a reasonable issue.
We should either allow a user to use $faker in anonymous function provider, or make DateTime format support in FakerWrapper, or both.
I'll try to fix it when I have time.
Feel free to ask more questions if you have them.
Thanks!
from db-seeder.
Hi @tebazil
First - your seeder is awesome!
Second - handling automatically DateTime by FakerWrapper would be great :)
from db-seeder.
@amjadsoftrove , @webvimark if that is possible to remember (years have passed), could you please tell why couldn't we use 'updated'=>$faker->dateTime() ?
That is s method call, and that should have worked.
from db-seeder.
Hello everyone,
Yes, the issue is still there:
Fatal error: Uncaught Error: Object of class DateTime could not be converted to string in /path/to/data-generator/vendor/tebazil/db-seeder/src/DbHelper.php:54
Stack trace:
#0 /path/to/data-generator/vendor/tebazil/db-seeder/src/DbHelper.php(35): tebazil\dbseeder\DbHelper->getParamsForEcho(Array)
#1 /path/to/data-generator/vendor/tebazil/db-seeder/src/Table.php(196): tebazil\dbseeder\DbHelper->insert('ordering_test', Array)
#2 /path/to/data-generator/vendor/tebazil/db-seeder/src/Table.php(98): tebazil\dbseeder\Table->insertData()
#3 /path/to/data-generator/vendor/tebazil/db-seeder/src/Seeder.php(50): tebazil\dbseeder\Table->fill()
#4 /path/to/data-generator/seeder.php(81): tebazil\dbseeder\Seeder->refill()
#5 {main}
thrown in /path/to/data-generator/vendor/tebazil/db-seeder/src/DbHelper.php on line 54
So, it's the Dbhelper#getParamsForEcho(...)
. The same error occurs in the Dbhelper#insert(...).
I solved that for me now with $value = $value instanceof \DateTime ? $value->format('Y-m-d H:i:s') : $value;
at both places. But it's just a hacky workaround and not a clean solution.
from db-seeder.
@automatix it is clear that DbHelper, which is responsible for db operation, should work with scalar values...
For the moment, I think we might fix this with some configurator hack...
Thanks for the feedback!
from db-seeder.
Related Issues (15)
- Can i seed the same table multiple times? HOT 2
- Is primary key hard-coded to "id"? HOT 3
- Missing feature to take all elements from a bag, not any one element twice HOT 1
- Missing support for valid() HOT 3
- PHP Version & non-Composer setup HOT 2
- the dependency lib is outdated .
- Disable truncating table for some cases HOT 2
- Don't insert into table HOT 3
- Junction Table relation HOT 1
- db-seeder stops working after a certain number of columns HOT 1
- Something went wrong... PHP Fatal error: Uncaught Error: Class 'tebazil\dbseeder\Seeder' not found in /home/work HOT 2
- Inserting Same Rows or Add providers in Faker Wrapper HOT 2
- Table data for table (table) column id is not found in class instance HOT 1
- Insert new record into existing table HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from db-seeder.