相关疑难解决方法(0)

Rails中has_one和belongs_to之间的区别?

我想了解has_oneRoR中的关系.

假设我有两个模型 - Person并且Cell:

class Person < ActiveRecord::Base
  has_one :cell
end

class Cell < ActiveRecord::Base
  belongs_to :person
end
Run Code Online (Sandbox Code Playgroud)

我可以只使用has_one :person,而不是belongs_to :personCell模型?

不一样吗?

ruby ruby-on-rails has-one

69
推荐指数
3
解决办法
4万
查看次数

Phalcon:1-1关系中的hasOne和belongsTo有什么区别?

我有 2 张桌子(2 个型号)

User
-uid
-email
-password
-(other fields)

Profile
-uid
-name
-age
-phone
-(other fields)
Run Code Online (Sandbox Code Playgroud)

他们有1-1的关系,我实现的关系如下:

class User extends Model
{
    public function initialize()
    {
        $this->hasOne('uid', 'Profile', 'uid');
    }
}

class Profile extends Model
{
    public function initialize()
    {
        $this->hasOne('uid', 'User', 'uid');
    }
}
Run Code Online (Sandbox Code Playgroud)

这个实现对吗?我可以用belongsTo替换hasOne吗?谢谢你的帮助!:-)

php model relationship phalcon

5
推荐指数
1
解决办法
4652
查看次数

标签 统计

has-one ×1

model ×1

phalcon ×1

php ×1

relationship ×1

ruby ×1

ruby-on-rails ×1