Member Price deletion

Source: Internet
Author: User

When a product is deleted, the member price corresponding to this item should also be removed from the member's price list.

Delete a member's price before deleting an item

Two methods:

Program implementation: "With this, extensibility comparison, do not need to modify the table structure"

protected function _before_delete ($option)
{
$id = $option [' WHERE '] [' id ']; The ID of the item to delete
/*************** Delete the original picture *******************/
Find out the path to the original picture first
$oldLogo = $this->field (' Logo,mbig_logo,big_logo,mid_logo,sm_logo ')->find ($id);
DeleteImage ($oldLogo);

/********** Delete Member Price *******/
$mpModel =d (' Member_price ');
$mpModel->where (Array (
' goods_id ' =>array (' eq ', $id),
))->delete ();
}

MYSQL comes with a foreign key:

Extension: How do I not use code deletion, and when I delete an item, the records in the member's price list are automatically deleted?

You can use the self-contained foreign KEY constraint in MySQL to implement the "premise: only InnoDB engine support"

drop table if exists p40_member_price;
CREATE TABLE P40_member_price
(
Price Decimal (10,2) is not null comment ' member prices ',
level_id mediumint unsigned not NULL comment ' level ID ',
goods_id mediumint unsigned not NULL comment ' Product ID ',
foreign KEY (goods_id) references P40_goods (ID) on DELETE cascade,
Key level_id (level_id),
Key goods_id (goods_id)
) Engine=innodb default Charset=utf8 comment ' member Price ';

Member Price deletion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.