3

i want to make an object from data from multiple related tables in my database,

do you know a better way?

Comments
  • 3
    There is always a better way: to avoid what you say you want in the first place. What's the goal in it, by the way? If it's SQL and you intend to combine values from related tables, there is (LEFT) JOIN.
  • 0
    @vintprox i want to cast sql results to a readable JSON file
  • 2
    @Afrographics learn SQL once, one language to query them all, in perspective less overhead. The less garbage you query, the better implications are 🙂
  • 0
  • 3
    Where's your query(s), this feels like it's queried incorrectly and then attempted to be mashed back together.
  • 2
    3 for-eaches in a single function are a bit of a red-flag to me

    You should be able to just query and join the data on SQL side and then a single cycle should be enough

    This feels like you did 3 queries for 3 tables and then tried to join them in code by going over all of them...

    That's probably what that first IF does...

    That's gonna be messy and slow as hell on bigger tables because it grows exponentially...
  • 0
    @Hazarth yes your right. Thanks 🤒
Add Comment