mysql父子节点分层_MySQL分层存储:搜索所有父/祖父母/等。给定一个子节点ID的节点?...

bd96500e110b49cbb3cd949968f18be7.png

I'm storing categories using a hierarchical model like so:

CATEGORIES

id | parent_id | name

---------------------

1 | 0 | Cars

2 | 0 | Planes

3 | 1 | Hatchbacks

4 | 1 | Convertibles

5 | 2 | Jets

6 | 3 | Peugeot

7 | 3 | BMW

8 | 6 | 206

9 | 6 | 306

I then store actual data with one of these category ids like so:

CARS

vehicle_id | category_id | name

-------------------------------

1 | 8 | Really fast silver Peugeot 206

2 | 9 | Really fast silver Peugeot 306

3 | 5 | Really fast Boeing 747

4 | 3 | Another Peugeot but only in Hatchbacks category

When searching for any of this data, I would like to find all child / grandchild / great grandchild etc. etc. nodes. So if someone wants to see all "Cars", they see everything with a parent_id of "Hatchbacks", and so everything with a parent_id of "Peugeot", and so on, to an arbitrary level.

So if I list a "really fast Peugeot 206" with a category_id of either 1, 3, 6, or 8, my query should be able to "travel up" the tree and find any higher categories which are parents/grandparents of that child category. E.g. a user searching for Peugeots in category "8" should find any Peugeots listed with categories 6, 3, or 1 - all of which category 8's descendants.

E.g. using the above data, searching for "Peugeot" in category 3 should actually find vehicles 1, 2 and 4, because vehicles 1 and 2 have a category ancestor trail which leads back up to category 3. See?

Sorry if I haven't explained this well. It's difficult! Thank you, though.

解决方案

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码是一个 `docker-compose.yml` 文件,用于定义一个多容器的 Docker 应用程序。主要分为三个部分,分别是版本信息、网络信息和服务信息,下面是详细的翻译: ``` version: '3' # 版本号 networks: # 网络配置 likeadmin: # 网络名 driver: bridge # 网络类型 services: # 服务配置 nginx: # nginx服务 container_name: likeadmin-nginx # 容器名 image: nginx:1.23.1 # 容器镜像 restart: always # 容器停止后自动重启 depends_on: # 依赖关系 - "php" # 依赖于php服务 volumes: # 挂载卷 - ../server:/docker_php/server - ./config/nginx/conf.d:/etc/nginx/conf.d - ./log/nginx/logs:/logs networks: # 网络 - likeadmin ports: # 端口绑定 - "80:80" php: # php服务 container_name: likeadmin-php image: likeshop/php:8.0.22-fpm restart: always working_dir: /docker_php/server volumes: - ../server:/docker_php/server networks: - likeadmin ports: - "9000:9000" user: "1000:1000" mysql: # mysql服务 container_name: likeadmin-mysql image: mysql:5.7.29 #X86架构 #image: amd64/mysql:5.7.29 #arm架构 restart: always environment: # 环境变量 MYSQL_ROOT_PASSWORD: root volumes: # 挂载卷 - ./data/mysql5.7.29/lib:/var/lib/mysql - ./config/mysql/mysqld.cnf:/etc/mysql/my.cnf networks: # 网络 - likeadmin ports: # 端口绑定 - "3306:3306" redis: # redis服务 container_name: likeadmin-redis image: redis:7.0.4 restart: always volumes: # 挂载卷 - ./data/redis:/data networks: # 网络 - likeadmin ports: # 端口绑定 - "6379:6379" node: # node服务 container_name: likeadmin-node image: node:14.18.1 restart: always volumes: # 挂载卷 - ../admin:/likeadmin_php/admin networks: # 网络 - likeadmin tty: true working_dir: /likeadmin_php/admin ports: # 端口绑定 - "5173:5173" ``` 这个 `docker-compose.yml` 文件定义了5个服务,分别是 `nginx`、`php`、`mysql`、`redis` 和 `node`,并且它们都在同一个网络 `likeadmin` 中。每个服务都有自己的 `container_name`、`image`、`restart`、`volumes`、`networks` 和 `ports` 等配置信息,其中 `depends_on` 用于定义服务之间的依赖关系。 希望这个翻译能够帮助你更好地理解这个 `docker-compose.yml` 文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值