![]() |
CodeIgniter 4 Model - One to Many - how to? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31) +--- Thread: CodeIgniter 4 Model - One to Many - how to? (/showthread.php?tid=80197) |
CodeIgniter 4 Model - One to Many - how to? - Scott103 - 09-27-2021 Hey guys, I am new to CodeIgniter 4 and self-taught, so for sure I am missing some skill or knowledge :-). Anyway - I am building simple quiz. One page will have multiple questions, and these questions will have multiple answers. I have three database tables for pages, questions and answers. Each of them has own Model. And I'm storing IDs of answers in questions table as json encoded aswers IDs. Same for questions IDs in pages table. Getting data for view is like scratching your left ear with your right hand. I am looping for json decoded arrays and finding items by IDs from other Model It is working well, but I am not sure that "this is the way". I was googling But I'm not sure how to do it the CodeIgniter. Can you kick me in the right direction? Thanks. RE: CodeIgniter 4 Model - One to Many - how to? - kenjis - 09-28-2021 Sorry, I can't your post. Would you fix the format? RE: CodeIgniter 4 Model - One to Many - how to? - InsiteFX - 09-28-2021 Your better off using pivot tables see the link below. Pivot Tables in MySQL Your data will start to run wild when it gets larger. RE: CodeIgniter 4 Model - One to Many - how to? - wdeda - 09-28-2021 I don't know if you've already done it, but let me suggest you take a look at data modeling, most of the time it can come up with solutions to your questions. RE: CodeIgniter 4 Model - One to Many - how to? - paulkd - 09-28-2021 (09-27-2021, 08:04 AM)Scott103 Wrote: Hey guys, Hi, You are new to CI. What are you comfortable with and what have you used previously? e.g. backend PHP or frontend JavaScript. CI is backend so your data would normally be recordsets and arrays, whereas json is usually for feeding into frontend JavaScript. So you shouldn't need to decode the data unless your are storing json in the table columns. I think you will only need one Model to create, read, update and delete your questions/answers data. |