PHP中的Ruby样式关系表

时间:2022-10-03 23:01:51

I know ruby (on rails) uses lots of "magic", but I use PHP, is there not a way of implementing the rails-like:

我知道ruby(在rails上)使用了很多“魔法”,但是我使用PHP,是不是有一种实现类似rails的方法:

class Player < ActiveRecord::Base
    has_many :cards
end

in PHP it would make so many peoples lives so much easier. Are there perhaps frameworks/ORM's that provide similar functionality etc?

在PHP中它会让很多人的生活变得如此简单。是否有框架/ ORM提供类似的功能等?

3 个解决方案

#1


2  

The term you're looking for is an "Object Relational Mapper" (ORM). The one you cite is a component of the Rails framework, called ActiveRecord.

您正在寻找的术语是“对象关系映射器”(ORM)。您引用的是Rails框架的一个组件,称为ActiveRecord。

PHP ActiveRecord is one project that attempts to provide this, though the last release was in July 2010. I haven't actually used it; I just switched to Rails. :)

PHP ActiveRecord是一个尝试提供此功能的项目,尽管最后一个版本是在2010年7月。我实际上没有使用它;我刚转到Rails。 :)

#2


2  

in CakePHP there are relationships such as hasMany, belongsTo, hasOne, and hasAndBelongsToMany

在CakePHP中有一些关系,例如hasMany,belongsTo,hasOne和hasAndBelongsToMany

#3


1  

PHP doesn't have a ORM by itself, but there are several fairly usable ORM projects for it; I'm acquainted with Propel, and it's rather good (used e.g. in the Symfony framework, which resembles Ruby somewhat).

PHP本身没有ORM,但有几个相当可用的ORM项目;我熟悉Propel,它相当不错(例如在Symfony框架中使用,类似于Ruby)。

#1


2  

The term you're looking for is an "Object Relational Mapper" (ORM). The one you cite is a component of the Rails framework, called ActiveRecord.

您正在寻找的术语是“对象关系映射器”(ORM)。您引用的是Rails框架的一个组件,称为ActiveRecord。

PHP ActiveRecord is one project that attempts to provide this, though the last release was in July 2010. I haven't actually used it; I just switched to Rails. :)

PHP ActiveRecord是一个尝试提供此功能的项目,尽管最后一个版本是在2010年7月。我实际上没有使用它;我刚转到Rails。 :)

#2


2  

in CakePHP there are relationships such as hasMany, belongsTo, hasOne, and hasAndBelongsToMany

在CakePHP中有一些关系,例如hasMany,belongsTo,hasOne和hasAndBelongsToMany

#3


1  

PHP doesn't have a ORM by itself, but there are several fairly usable ORM projects for it; I'm acquainted with Propel, and it's rather good (used e.g. in the Symfony framework, which resembles Ruby somewhat).

PHP本身没有ORM,但有几个相当可用的ORM项目;我熟悉Propel,它相当不错(例如在Symfony框架中使用,类似于Ruby)。