Article table layout

I need to create a typical crud application for “articles”, is there a standard or kind of best practice when it comes to this? I know that every application and situation is different, but I mean in general.

Secondly, I was a little confused about how to process several images associated with a certain article, I thought that only img tags scattered throughout the body of the article, as opposed to a table of images and links to images and articles and all that. Just find some tips and suggestions on how to handle such things, as I'm sure most of us here have done this several times.

Defining my article as is:

CREATE TABLE `articles` ( `id` int(11) NOT NULL auto_increment, `issue_id` int(11) default NULL, `status` text, `updated_at` date default NULL, `body` text, `title` varchar(255) default NULL, `author` varchar(255) default NULL, `created_at` date default NULL, PRIMARY KEY (`id`) ) 
+4
source share
3 answers

Dublin Core is an unofficial standard set of attributes for documents and media. Attributes

  • Title
  • Creator
  • Theme
  • Description
  • Publishing house
  • Author
  • the date
  • A type
  • Format
  • Identifier
  • A source
  • Tongue
  • Communication
  • Coating
  • The rights

One can hardly think of the people who have worked on document / media management applications for many years. I think this is a good resource for scanning ideas of what attributes your users might find valuable that you might miss at the beginning (for example, creator versus publisher and contributor versus source). I would not just dump all this into your application, without thinking about how relevant they are.

I think you need a table that links images to articles. Otherwise, if you need to know what images the article uses, for example, to delete an article and its images, the only way to find related images is to analyze the subject of the article itself. This results in inconvenient SQL using string processing functions or forced processing in your application, which can be a performance issue if you need to process a group of articles at once.

You can still use only image tags in the body of the article to layout images, avoiding the more complex customizable markup system. Just write your model so that it analyzes image tags and updates the connection table when creating / editing an article. A little nokogiri and attachment_fu (or their alternatives) should do it quickly.

+2
source

Article table:

 CREATE TABLE `articles` ( `id` int(10) unsigned NOT NULL auto_increment, `keyname` varchar(96) NOT NULL, `title` varchar(96) NOT NULL, `content` text NOT NULL, `tags` varchar(128) NOT NULL, `author` varchar(128) NOT NULL, `date_created` datetime NOT NULL, `date_updated` datetime default NULL, PRIMARY KEY (`id`) ) 

Article Images:

 CREATE TABLE `articles_images` ( `id` int(10) unsigned NOT NULL auto_increment, `article_id` int(10) unsigned NOT NULL, `url_thumb` varchar(512) NOT NULL, `url_big` varchar(512) NOT NULL, `date_created` datetime NOT NULL, PRIMARY KEY (`id`), KEY `article_id` (`article_id`) ) 

url_thumb - image thumbnail
url_big - large image

And you can check the wordpress chema database

+1
source

If you just want to display images and upload them using ftp, the subject of the image tag will be good

If you want the web interface to load them, saving paths to the database is very convenient

You do not need to attach images to the article as such, you can have a table that stores the image paths, and then use the join model or just point to the images through the image tag

This allows you to use something as convenient as a paperclip (plugin) for handling loading and storage.

0
source

Source: https://habr.com/ru/post/1285704/


All Articles