Git Product home page Git Product logo

Comments (6)

tebazil avatar tebazil commented on July 17, 2024 1

@webvimark , thanks!

handling automatically DateTime by FakerWrapper would be great
Noted. I plan to add it during this month.

from db-seeder.

tebazil avatar tebazil commented on July 17, 2024

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:

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.

webvimark avatar webvimark commented on July 17, 2024

Hi @tebazil
First - your seeder is awesome!
Second - handling automatically DateTime by FakerWrapper would be great :)

from db-seeder.

tebazil avatar tebazil commented on July 17, 2024

@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.

automatix avatar automatix commented on July 17, 2024

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.

tebazil avatar tebazil commented on July 17, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.