Not a developer? Go to MovableType.com

Documentation

Getting and Storing Data for a Custom Data Type

Once you have registered and defined your custom object type. You can easily save instances of the object, or retrieve and/or delete them from the database. Here are some very simple code samples which cover the basics of retrieving and storing these custom objects from the database:

Inserting Data

my $object = TestPlugin::SuperHappyVideo->new;
$object->blog_id(1);
$object->title("My latest video");
$object->length(120);
$object->description("The best video in the world.");
$object->save;

Loading and Updating Data

my $object = TestPlugin::SuperHappyVideo->load({ id => 4 });
$object->title("My latest HAPPY video!");
$object->save;

Deleting Data

my $object = TestPlugin::SuperHappyVideo->load({ id => 4 });
$object->remove;

There are a number of different functions Movable Type makes available to you to make it easier to query and manipulate data in the database. Some of these functions are:

  • load
  • load_iter
  • get_by_key
  • remove
  • remove_all
  • remove_children
  • save
  • set_by_key
  • init
  • join
  • unique
  • count
  • count_group_by
  • exists

For complete documentation on creating custom objects, please consult Appendix B.

Back

Leave a Comment