Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __________________Method 1__________________
- post[23](
- int_tag=15---------------------
- string_content="Some post" |
- id_owner=1 |
- date=123456) |
- |
- ----------------------------
- |
- |
- V
- tag_assoc[15]( ----> tag_assoc[17]( ---------> tag_assoc[18](
- id_tag=12------- | id_tag=20--------- | id_tag=21-----------
- id_owner=1 | | id_owner=3 | | id_owner=2 |
- int_flink=17---|------ int_flink=18-----|------ int_flink=0 |
- ) | ) | ) |
- | | |
- ----------- | |
- | | |
- V V V
- tag[12]( tag[20]( tag[21](
- string_name=cats string_name=dogs string_name=technology
- id_owner=20 id_owner=5 id_owner=2
- date=123456) date=10000) date=16116)
- __________________Method 2__________________
- // The struct in array_tags is id_owner,id_tag.
- // The array_tags field is stored in the database as TEXT or VARCHAR
- post[23](
- array_tags=[
- 1,12-----------------
- 3,20----------------|--------------------------------------------------------------
- 2,21----------------|------------------------- |
- ] | | |
- content="Some post" | | |
- owner=1 | | |
- date=123456) | | |
- | | |
- | | |
- ----------------- | |
- | | |
- V V V
- tag[12]( tag[20]( tag[21](
- string_name=cats string_name=dogs string_name=technology
- id_owner=20 id_owner=5 id_owner=2
- date=123456) date=10000) date=16116)
- *** What about searching BY tag? We will need a lookup table with either Method 1 or Method 2!
- __________________Method 3__________________
- // from: http://stackoverflow.com/questions/20856/how-do-you-recommend-implementing-tags-or-tagging
- // also used in the toxi solution: http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html
- // This solution will satisfy both
- // a) returning all tags for a post
- // b) returning all posts for a tag
- // Downfall: For both searching by post or searching by tag, or retreiveing all tags for a post,
- // the entire tag_assoc table must be searched.
- post[23](
- string_content="Some post"
- id_owner=1
- date=123456)
- ^
- |
- -------------------------------------------------------------------------------
- | | |
- tag_assoc[15]( | tag_assoc[17]( | tag_assoc[18]( |
- id_post=23----- id_post=17-------- id_post=17----------
- id_owner=1 id_owner=3 id_owner=2
- id_tag=12------| id_tag=20--------- int_tag=21----------
- ) | ) | ) |
- | | |
- ----------- | |
- | | |
- V V V
- tag[12]( tag[20]( tag[21](
- string_name=cats string_name=dogs string_name=technology
- id_owner=20 id_owner=5 id_owner=2
- date=123456) date=10000) date=16116)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement