From Newsgroup: comp.databases.mysql
On 09/11/2019 23.05, ^Bart wrote:
Think this one better fits in a database related usegroup like
comp.databases.mysql
I'm sorry, you're right!
You are creating a one to one relation between the ingredients and
recipes, you need a table in between to join
Do you mean something like this:
ingredient
-------------------
id_ingredient name
1-a-a-a-a-a-a-a-a-a sugar
2-a-a-a-a-a-a-a-a-a eggs
3-a-a-a-a-a-a-a-a-a-a-a-a flour
recipes
------------------
id_recipe name
1-a-a-a-a-a-a-a-a pasta "X"
ingredientrecipes
-------------------
id_ingredientrecipe id_ingredient id_recipe 1-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a 2-a-a-a-a-a-a-a-a-a-a-a-a 1 2-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a-a 3-a-a-a-a-a-a-a-a-a-a-a-a 1
Almost, drop the id_ingredientrecipe, there is zero use of it. and you
want to make (id_ingredient, id_recipe) to the primary key. You may want
to have column for the amount of the ingredient.
recipes_ingredients which has two columns, id_recipe and
id_ingredient. and you remove the FK_id_ingredient (bad naming of the
column) as it's not needed.
Ok, in my mind it helps to show me it's a FK!
That you will see when you do a "describe ingredientrecipes;", also the assumption is that columns with the same name in a table which don't
contain information but a reference would be foreign keys.
I would suggest you have English as part of your languages in the
languages table, the ingredients will have a translation_key instead
of the name. Then you have exactly the same code in your front end to
display the names regardless of language. Makes your code easier to
maintain.
[CUT]
Having all languages in a table makes it simple, you just pick the
languages in the order the user prefers and the fall back language
last and you just pick the first line you get.
I should replace the tables ingredient and ingredienttranslations just
with one table where I should store all translation ingredients:
languages
------------------
id_language name
1-a-a-a-a-a-a-a english
2-a-a-a-a-a-a-a italian
3-a-a-a-a-a-a-a-a-a-a french
4-a-a-a-a-a-a-a-a-a-a spanish
ingredients
-------------------------
id_ingredients name-a-a-a-a id_language translation_key 1-a-a-a-a-a-a-a-a-a-a-a-a-a eggs-a-a-a-a 1-a-a-a-a-a-a-a-a-a-a 1 2-a-a-a-a-a-a-a-a-a-a-a-a-a uova-a-a-a-a 2-a-a-a-a-a-a-a-a-a-a 1 3-a-a-a-a-a-a-a-a-a-a-a-a-a flour-a-a-a 1-a-a-a-a-a-a-a-a-a-a 3 4-a-a-a-a-a-a-a-a-a-a-a-a-a farina-a-a 2-a-a-a-a-a-a-a-a-a-a 3
languages
language_id name
translation_keys
translation_key_id translation_key
translations
language_id translation_key_id text
ingredients
ingredient_id translation_key_id
The translations table can hold any type of text, ingredient, recipes or
free text that you use in other part of the site.
But in this case it's more complicated to enable the add feature just if
you add an ingredient in english before because just after this step
you'll be able to connect a translation to the languages needed!
The only complication here is that you need to do a few more inserts
when you add something. For the automated part it don't matter if the translation_key is in language X or Y.
No matter what you do, you will have a complication with allowing others
add what they want, as you will not be able to match muna with |ngg
unless you only allow them to translate from a predefined language like english, or you force them to always have the english translation.
Alternative is to a word table, you then have the id, name, and the
language columns, then you have another table where you have meaning
with an id and description. Then you have a table for joining the
meaning and the word, but you can't auto add anything to this, you have
to have someone to match the words together.
If I have a table with all english ingredients I must add other
ingredients in the ingredienttranslation table just if there's a key to
the english version without to write a particular code!
And if someone wants to add pU+peepeo and you don't have mirin in your english list?
Or what if you have mirin in your english list but no translations and
the person who writes the recipe don't know English (quite common in
Japan), then how do they add pU+peepeo?
You are to English fixated, think about your whole project was in
Japanese and you would have to add English. Translations will never be
easy specially if you allow user input.
Or maybe I didn't understand what you said... :\
A numeric key is better than string based key.
I think Jerry already explained all this once before.
Yes of course but... if this is the best practice I don't understand
why, also in other newsgroup, someone would like to drop id column and replace it with two primary key formed by string field!
For they are less skilled than Jerry.
I think the best answer could be "to drop id column could be a good
solution but you'll have bad performance than to have an id column!",
just Jerry Stuckle said something like this...
Se, he has the experience, so you should listen to him.
--
//Aho
--- Synchronet 3.21d-Linux NewsLink 1.2