0

I gather how to create the database via an XML via https://devdocs.magento.com/guides/v2.4/extension-dev-guide/declarative-schema/db-schema.html

and using bin/magento setup:db-declaration:generate-whitelist module_name to generate the whitelist and bin/magento setup:upgrade to install the changes.

What I can't find is how to get data from the database in magento 2.4.

I found https://magento.stackexchange.com/a/303748/662 and https://www.mageplaza.com/magento-2-module-development/how-to-create-crud-model-magento-2.html which details how to set up a method that loads database items automatically when fetched via a page, but that is useless when you need certain models fetched without automatic insertion.

But how about direct queries that return models. Does magento 2 have a method like laravel's eloquent to do queries to fetch database model instantiated objects directly when needed via a query, or is this crude method the only way to fetch data? https://www.rakeshjesadiya.com/direct-sql-queries-in-magento-2/

1 Answer 1

0

There are a few ways to get the data you need. Personally, I use https://mage2gen.com/ to create the module and its models, because it's a solid starting point. I'd recommend generating a module with a model and looking at the formatting.

I'll update this answer shortly to include details on what is required, but the above link can generate pretty usable code in the meantime.

3
  • right... using a generator... I'm currently in the process of writing a plugin to automate stuff, github.com/tschallacka/mage2-magecommands but man, magento is rough compared to laravel, octobercms and wintercms, it feels as if I've been set back in time 7 years Commented Apr 21, 2021 at 15:52
  • 1
    Yeah the learning curve is steep. They have their own way of doing things, but once you start figuring it out, its not too bad.
    – Hunter
    Commented Apr 21, 2021 at 15:54
  • I don't mind the automatic stuff etc, that's all pretty okay. It's the fragmented documentation that's a pain to work through. Commented Apr 21, 2021 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.