-1

I have the following tables:

  1. Organization.
  2. Articles
  3. Templates

Organization is the parent of both articles and templates.

On the articles index page, I display (by default) all templates for the organization.

Here's my problem. How do I add the ability to customize which templates are shown for each article?

I could create a ArticleTemplates table that has the following schema:

  1. id
  2. article_id
  3. template_id
  4. included_on_article (boolean field that indicates if the template should be included on the article)

But then I see problems with this:

  1. Adding new records to ArticleTemplates seems clunky, as it would have to change every time a new template was added to the organization.
  2. As every article usually will have all templates, there will be a lot of records in ArticleTemplates that are the same.

Any better solutions?

  • As every article usually will have all templates, there will be a lot of records in ArticleTemplates that are the same. -- Not true. The combination of id, article_id and template_id should be unique for any given record. – Robert Harvey May 30 '18 at 17:04
  • @RobertHarvey, You are correct. I meant that it seems like a lot of duplication in the records, not that they are exactly the same. – NathanB May 30 '18 at 17:25
  • It's a linking table, containing only ids. I don't think you should be concerned about the number of records in it. – Robert Harvey May 30 '18 at 17:27
  • @RobertHarvey, One of my problems is that there are lots of articles. If a user were to create a new template, I would have to create a new ArticleTemplate for each article (potentially thousands). Is there not a better way? – NathanB May 30 '18 at 17:35
  • But that's the reason you do this in a linking table. I know you called this table ArticleTemplates, but they're not really templates. Each one of these records is probably only about 32 bytes in size, and databases can handle billions of records in each table. – Robert Harvey May 30 '18 at 17:43
0

You don't need to have boolean field in ArticleTemplates table for indicating if tempalte should be included to article.

Because you mentioned As every article usually will have all templates - you can create "aggregate" table which will contains only templates excluded from articles

ExcludedTemplates
    ArticleId
    TemplateId

In the application you will create a scope which load only article's templates which not exists in ExcludedTemplates table.

With this approach new template will be automatically included in all articles without creating thousands of new records.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.