将多个图像保存在数据库中的最佳方法
The best way to keep multiple images in database
我在 Rails 上使用 Ruby 和 postgresql,我看到两个选项:
- 模型有字段图像,其类型是json(并将它们保存为数组)。
- 型号 has_many_and_belongs_to 相关型号如 "Image"。
这两个哪个更可取?
I consider performance as the first and convenience as the second.
我会问自己这个问题。
图片是否仅与 1 个模型相关?
如果,它只会与 1 个模型相关,例如个人资料图片。然后,它将最适合第一种方法
Model has field image, which type of is json (and keep them as array).
如果图像将用于多个模型,如表情符号或 letter_avatar。然后,它将适合第二种方法
Model has_many_and_belongs_to related model like "Image".
在性能方面,第一种方法会更好。您不必花费资源来获取相关模型。
我在 Rails 上使用 Ruby 和 postgresql,我看到两个选项:
- 模型有字段图像,其类型是json(并将它们保存为数组)。
- 型号 has_many_and_belongs_to 相关型号如 "Image"。
这两个哪个更可取?
I consider performance as the first and convenience as the second.
我会问自己这个问题。 图片是否仅与 1 个模型相关?
如果,它只会与 1 个模型相关,例如个人资料图片。然后,它将最适合第一种方法
Model has field image, which type of is json (and keep them as array).
如果图像将用于多个模型,如表情符号或 letter_avatar。然后,它将适合第二种方法
Model has_many_and_belongs_to related model like "Image".
在性能方面,第一种方法会更好。您不必花费资源来获取相关模型。