I’ve got a question about CakePHP and databases regarding an application idea I have. I’m still only at the first lines of code, but I’m trying to think out what it will require from CakePHP. One of the things I’ve realized is the structure of this application will require runtime table creation, which won’t work because I need to bake.
Allow me to explain. There’s a parent object called the list. The list has many submissions, it also has many comments. Basically users submit an item to the parent list, and they can also comment on the parent list. The things I’m having trouble figuring out is how I’d structure all of this.
My first thought was to have a table containing a row for each list, with it’s basic properties. Then two tables per list containing lists submissions and comments. I’m not sure what kind of relationship the comments and submissions table should have to the row in the lists table containing the parent info, foreign key?
The problem with this approach is when a user creates a new list, this would require the creation of two new tables associated with that list. I don’t see that this is possible in CakePHP due to needing a bake to generate the cake structure. My other thought was if Cake allowed me to access arbitrary tables without established models, I could access everything, but then I would have to define all the relationships at every point I rely on them.
I’m not really sure how to approach this, any help is appreciated.
You don’t need to add new tables every time as you suggested above. You should have 3 tables,
lists,list_submissions, andlist_comments. When someone adds a list, you add a row to theliststable.list_submissionsandlist_commentsshould have alist_idfield as a foreign key, so when a new comment or submission is added, just save the id of the list it belongs to in the appropriate table. YourListSubmissionandListCommentshould have a ‘belongs to’ relationship with theListmodel.