Skip to content

Tag and ObjectTag Table Reference

mikert edited this page Feb 15, 2011 · 1 revision

Tag Tables

Associated Perl objects

  • MT::Tag
    • Stored in mt_tag
  • MT::ObjectTag
    • Stored in mt_objecttag

Tag Table Fields

  • tag_id - integer not null auto_increment primary key. Tag's primary key
  • tag_name - string(255) not null. The tag's name. This is what is displayed by <$mt:TagName$>
  • tag_n8d_id - integer. Used to point to the tag which is the "normalized" form of a given tag. A normalized tag is one that's been purged of punctuation and white space.
  • tag_is_private - boolean. Used to denote whether or not the tag should be displayed on the published site. Tags prefixed with "@" are private by default.

Object Tag Table Fields

  • objecttag_id - `integer not null auto_increment'. The Object Tag's primary key.
  • objecttag_blog_id - `integer'. The ID of the blog where the Tag:Object association is made.
  • objecttag_object_id - `integer not null'. The ID of the object in its table that is associated with a particular tag.
  • objecttag_object_datasource - `string(50) not null'. The "datasource" of the object. This is the name of the object's table minus the mt_ prefix.
  • objecttag_tag_id - `integer not null'. The ID of the tag associated with the object.

Developer Tips

SQL Lookup Of Entries Tagged "Melody" In a Blog

select entry_title 
    from mt_entry entry 
    join 
        mt_objecttag otag
        on
        entry.entry_id = otag.objecttag_object_id 
        and
        otag.objecttag_object_datasource = 'entry' 
        and
        entry.entry_class = 'entry' 
    join
        mt_tag tag
        on
        otag.objecttag_tag_id = tag.tag_id
        and
        tag.tag_name = 'melody';

MT::Object Join

# Load non-normalized tag 'melody', fetch only its primary key and then call the "id" method
my $tag_id = MT->model('tag')->load({ name => 'melody', n8d_id => 0 }, { fetch_only => ['id'] })->id;
my @entries = MT->model('entry')->load({
         blog_id => 10
    }, { 
            #Join on mt_objecttag where entry_id == object_id
            'join' => MT->model('object_tag')->join_on('object_id', 
                                                        {
                                                            id => $tag_id,
                                                            blog_id => 10
                                                        } 
                                                   )
       }
);
Clone this wiki locally