The logic of establishing a counterparty and at the same time ordering



  • Help, lick, figure out how to correctly define: In order to create a card, a client must be attached to it (he may be repetitive or new). There's only one thing in my head-- first create a client (or re-set) and then make an order. Can we combine these two stages?



  • Without the BDE structure, it's definitely a coffee pot, but I'll try. Let's offer you this type of OBD structure.

    -- справочник заказов
    CREATE TABLE orders (
      id bigint not null auto_increment,
      name varchar(255)
      ...
    );
    -- справочник клиентов
    CREATE TABLE clients (
      id bigint not null auto_increment,
      name varchar(255) not null,
      jur_address varchar(255),
      real_address varchar(255),
      ...
    );
    -- связка заказов с клиентами (один-ко-многим)
    CREATE TABLE lnk_client_orders (
      id bigint not null auto_increment,
      client_id bigint int not null,
      order_id bigint int not null,
      ...
    );
    

    Let's say you made the order. Now it needs to be tied to a client, but you don't know him until you've created or got it from the OBD system. Everything you described. There are two exits:

    1. Traditional - ordering, reminiscing EDEDs, creating/recruiting a client - resemble ED. We link these two IDs through the bundle table.
    2. Writing on the side of the OBD procedure create_order where we transmit the order and the client data, and she's already inside herself deciding what to create or get and how to connect.
    CREATE PROCEDURE create_order
    (
    order_name varchar(255),
    client_id bigint,
    client_name varchar(255),
    ...
    )
    BEGIN
    DECLARE order_id bigint;
    INSERT INTO orders (name) VALUES(order_name);
    SELECT INTO @order_id LAST_INSERT_ID();
    -- если указан client_id получаем о нем информацию (проверяем что такая запись есть)
    -- если он не указан - создаем нового клиента, получаем ID
    -- по аналогии с order_id и связываем клиента и заказ путем
    -- INSERT в таблицу-связку
    END;

    In my view, it is preferable that the second option is that decide for you most of the verification problems - plus its implementation is hidden. под капотомwhich will not allow чур меня - hacking the site - understand how and what you're up to, and then you're doing something in order.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2