From a purely logic approach you need a separated table "keywords" if
you think that a keyword is a
object (or an entity). With two table you can put in "article_keywords"
anything you want, with tree tables
you enforce the meaning of keyword as an object, and you limit the
allowed keywords to a defined set.
In a successive time with 3 tables is possible add to the keyword table
new fields as "keyword_category"
and search all the articles that are in category, eg have a keyword in a
given set, or is possible add new
fields eg "score" to the link table "articlekeywords_table"
If you think that these features are useful for you use 3 tables, else I
think there is no bad use
only 2.
Ezio
Martin Stein wrote:
> Hi all,
>
> Just a short question concerning database design in general and
> SQLAlchemy in particular. Let's take the many-to-many example from the
> docs (chapter Data Mapping), where we have a table containing articles
> and one containing some keywords. Now, I understand the normal layout of
> such a many-to-many relationship: Create 2 separate tables (in this case
> "articles " and "keywords") and create the relationship link using a 3rd
> table ("articlekeywords_table").
>
> I was wondering: In this special case, where one end of the relationship
> consists of very "small" objects - essentially, each keyword object is
> not more than a string - why shouldn't I simply use a one-to-many
> structure like this:
>
> articles_table = Table('articles', metadata,
> Column('article_id', Integer, primary_key = True),
> Column('headline', String(150), key='headline'),
> Column('body', TEXT, key='body'),
> )
>
> my_keywords_table = Table('article_keywords', metadata,
> Column('article_id', Integer, ForeignKey("articles.article_id")),
> Column('keyword_string', String(50))
> )
>
> I am aware that this is not a db-layout which is normalized like the
> theory says you should, but in this special case where the second end of
> the relationship only consists of single strings... why not? What is the
> advantage of the "classic" many-to-many way of doing it?
>
> Probably, I am missing something, so I would appreciate if someone could
> tell me the flaw in my thinking.
>
> Thanks and Cheers,
> Martin
>
>
>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Sqlalchemy-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
>
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users