外交关系中的可打行为原则
我有一个数据库设计案例,我很好奇 Doctrine ORM 是否支持开箱即用。
产品:
列:
id: {类型:整数,主值:true,自动增量:true }
type_id: { 类型:整数,notnull: true }
brand_id: { 类型:整数,notnull: true }
关系:
产品类型:
类:产品类型
本地:type_id
国外:id
品牌:
类别:品牌
本地:brand_id
国外:id
产品类型:
充当:
I18n:
字段:{ 名称 }
列:
id: {类型:整数,主值:true,自动增量:true }
名称: { 类型: string(255), notnull: true }
品牌:
充当:
I18n:
字段:{ name }
列:
id: {类型:整数,主值:true,自动增量:true }
name: { type: string(255), notnull: true }
我想对 Products 表进行 slugify,即。产品将通过它们的段头到达。然而,正如您所看到的,品牌和产品类型表都有国际化行为。而且,产品没有名称。产品的别名将为:“Brand.name - ProductType.name”,并随所提供的语言而变化。
对于这种情况,我是否可以使用 Doctrine 的 Sluggable 行为来自动对我的产品进行 Sluggify。或者我必须手动管理它?
顺便说一下我的环境配置是:
教义版本:1.2
Symfony:1.4.1
谢谢
I have a database design case which I am curios whether Doctrine ORM supports it out-of-box.
Product:
columns:
id: {type: integer, primary: true, autoincrement: true }
type_id: { type: integer, notnull: true }
brand_id: { type: integer, notnull: true }
relations:
ProductType:
class: ProductType
local: type_id
foreign: id
Brand:
class: Brand
local: brand_id
foreign: id
ProductType:
actAs:
I18n:
fields: { name }
columns:
id: {type: integer, primary: true, autoincrement: true }
name: { type: string(255), notnull: true }
Brand:
actAs:
I18n:
fields: { name }
columns:
id: {type: integer, primary: true, autoincrement: true }
name: { type: string(255), notnull: true }
I want to slugify Products table, ie. products will be reached via their slugs. However, as you see both brand and productype tables has i18n behaviour. And moreover, product doesnt have a name. A product's slug will be: "Brand.name - ProductType.name", and vary with the language served.
For this scenario, is there anyway I can use Sluggable behaviour of Doctrine to sluggify my products automatically. Or do I have to manage it manually?
By the way my environment configuration is:
Doctrine Version: 1.2
Symfony: 1.4.1
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的理解是,您需要在产品类型和品牌模型中都有别名。您可以保留产品定义不变。不管怎样,我从你的问题中假设每个品牌+类型只有一种产品(即使它没有多大意义)。因此 ProductType 和 Brand 将定义如下:
然后您必须配置 Product 路由以使用 slugs。之后,您将需要配置操作来检查从路线中获得的内容。
例如,这可能是您的产品路线:
然后在操作中您将调用您自己的 findOneBySlugs($brand_slug, $type_slug) 方法:
My understanding is that you need to have the slug in both Product Type and Brand models. You can leave the Product definition as it is. Anyway, I'm assuming from your question that there is only one product for every brand+type (even if it doesn't have to much sense). So ProductType and Brand will be defined like this:
Then you have to configure your Product route to use the slugs. And after that you will need to configure the action to check what you are getting from the route.
For example, this could be your route for Products:
Then in the action you will call to your own findOneBySlugs($brand_slug, $type_slug) method:
该解决方案的问题是查询。与:
如果我没记错的话,您正在执行 5 连接查询。您可以改进为只执行三个(产品、品牌翻译和产品类型翻译)
我处于类似的情况,最好的选择是在本例中使用品牌或产品类型名称为每个产品创建一个别名。所以你只需要:
我正在考虑两个选项:
或者在记录类上使用 getUniqueSlug() 函数。我认为第一个选项是最好的,因此您不必担心唯一性。
the problem with that solution are the queries. With:
you are doing a 5-join query if I'm not mistaken. You can improve to do only three (product, brand_translation and producttype_translation)
I'm in a similar situation, and the best option is to create a slug for each product using the brand or product type name in this case. So you would only need:
I'm thinking between two options:
or using the getUniqueSlug() function on the record class. I think the first option is best so you don't have to worry about uniqueness.