Welcome Guest, Not a member yet? Register   Sign In
Entities and relationship
#1

Greetings people,


I'm new to Code Igniter 4 ans after browsing your documentation, I have a question that hasn't found its answer yet. I would like to know what is the proper way to deal with foreign keys when we are working with entities.

Let's take an example: I have a table for books, and a table for authors. Obviously, the books table will have a foreign key toward the author table.
If I ask my model to perform a $bookModel->find(1) I will get the book id #1 from the table, and the ->getAuthor() method will get me an ID, like let's say 9

Now, I don't much care about this ID. What I really want is the name of the author, which is set in the "name" column of the author table.
How do you properly get that? Do I really have to send another query, like "authorModel->find(9)" ? that would be very very heavy in the end, in term of sql queries amount....
Or is there another way more classy option?

note: I know there are ORMs working with CI4 which would solve this problem. But due to the structure of the database I currently have to work with, none of them would work (I am using mysql, and all the data are split between multiple bases - as in sql "CREATE DATABASE"- , with tons of relationship between them. While all ORMs I have found requires to connect specifically to only one of them)
Reply


Messages In This Thread
Entities and relationship - by Skem - 10-14-2021, 01:42 AM
RE: Entities and relationship - by includebeer - 10-16-2021, 07:09 AM
RE: Entities and relationship - by MGatner - 10-23-2021, 05:04 AM
RE: Entities and relationship - by mlurie - 10-26-2021, 09:09 AM
RE: Entities and relationship - by manager - 10-31-2021, 09:44 PM
RE: Entities and relationship - by foxbille - 12-18-2021, 10:14 AM
RE: Entities and relationship - by stopz - 12-20-2021, 02:33 PM
RE: Entities and relationship - by groovebird - 07-05-2022, 11:53 PM
RE: Entities and relationship - by kilishan - 07-06-2022, 06:33 AM



Theme © iAndrew 2016 - Forum software by © MyBB