Pregunta

Having two tables one that holds articles and another that holds custom fields for those articles with a relation of one article to many custom fields.

How efficient is it to do a join for each field in order to get the whole data in one go?

Or is there a better way of doing this that would allow the custom fields to be used in where clause?

I am considering this or altering the table schema to accommodate the custom fields.

¿Fue útil?

Solución

If you need to filter articles by a custom property you can do:

SELECT * FROM Article WHERE IDArticle IN(SELECT IDArticle FROM ArticleCustomProp WHERE CustomFieldValue='value')

If you need to get and Article with all its custom properties you can do:

SELECT * FROM Article A LEFT JOIN ArticleCustomProp CP ON A.IDArticle=CP.IDArticle
WHERE A.IDArticle=15

One problem that you have here is field type. In your ArticleCustomProp you can have:

  • IDArticle (INT)

  • CustomPropertyName (STRING)

  • CustomPropertyValue (?)

The problem is what type to give to CustomPropertyValue field. If you need to mix multiple types values you have to find a generic way to save data to this field, regardless the data type. Hope it helps you. Let me know if i can assist you with anything else.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top