I’m struggling to get the relations right for some reason on some tables I’m trying to setup today. I’m building an app which allows posting of articles and maintaining older versions. My intent is to have an ‘articles’ and ‘article_versions’ table. The article_versions table will have an article_id table that points to articles.id.
My thinking is I want to add a current_version_id on the articles table, but I'm not sure how I should define that relationship. As of now I have an article that belongsTo article_versions. This muddles up my creation process though. As of now I'm overloading save() to do the following:
This mostly works but feels pretty kludgey. Ideally these are the final things I want to achieve:
Any thoughts or suggestions would be appreciated.
Hi trahma,
interesting problem. From your question is not clear to me where the content of a specific article version is stored. I think two tables are enough. Let's keep the table names article and article_version. I would define them as article - id, title, ... article_version - article_id, version, creation_time, content article hasMany article_versions. It makes sense to me also to have a 'relationship' where you only take the version names without the content.
Hope this helps
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community