Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RubyonRails:当连接模型使用一个所属对象时,如何通过关联来构造一个has\u-many_Ruby On Rails_Activerecord_Associations - Fatal编程技术网

Ruby on rails RubyonRails:当连接模型使用一个所属对象时,如何通过关联来构造一个has\u-many

Ruby on rails RubyonRails:当连接模型使用一个所属对象时,如何通过关联来构造一个has\u-many,ruby-on-rails,activerecord,associations,Ruby On Rails,Activerecord,Associations,我正在尝试创建一个has\u many,当连接模型使用一个belown\u to时,通过关联 示例如下: class User has_many :projects, through: :project_memberships end class ProjectMembership belongs_to :project end class Project has_many :project_memberships end Rails告诉我此关联无效。如果无法使用:通过此处的关

我正在尝试创建一个has\u many,当连接模型使用一个belown\u to时,通过关联

示例如下:

class User
  has_many :projects, through: :project_memberships
end

class ProjectMembership
  belongs_to :project
end

class Project
  has_many :project_memberships
end

Rails告诉我此关联无效。如果无法使用
:通过此处的关联,使用ActiveRecord访问用户拥有成员资格的所有项目的最佳方式是什么?

用户必须与
项目成员资格相关,例如:

class User
  has_many :project_memberships
  has_many :projects, through: :project_memberships
end

class ProjectMembership
  belongs_to :project
  belongs_to :user
end

class Project
  has_many :project_memberships
end

查看有关关联的更多信息。

用户必须与
项目成员身份相关,例如:

class User
  has_many :project_memberships
  has_many :projects, through: :project_memberships
end

class ProjectMembership
  belongs_to :project
  belongs_to :user
end

class Project
  has_many :project_memberships
end

检查有关关联的详细信息。

ActiveRecord::StatementInvalid:PG::UnfinedFunction:错误:运算符不存在:整数=字符变化行1:…在“项目”上加入“项目成员身份”。“id”=“项目…^提示:没有与给定名称和参数类型匹配的运算符。您可能需要添加显式类型转换:从“项目”中选择“项目”。*在“项目”中的“项目”内部加入“项目成员身份”。“id”=“项目成员身份”。“项目id”中的“项目成员身份”。“用户id”=“1这是我在更新代码时遇到的错误。知道问题出在哪里吗?找到答案了。我把我的ID存储为字符串(哎呀!)。感谢您提供帮助ActiveRecord::StatementInvalid:PG::UndefinedFunction:错误:运算符不存在:整数=字符变化第1行:…在“项目”上加入“项目成员身份”。“id”=“项目…”^提示:没有与给定名称和参数类型匹配的运算符。您可能需要添加显式类型转换。:选择“项目”。*从“项目”中的“项目”内部加入“项目成员身份”。“id”=“项目成员身份”。“项目成员身份”中的“项目成员身份”。“用户id”=$1这是我更新代码时遇到的错误。知道可能是什么问题吗?解决了。我的id存储为字符串(哎呀!)谢谢你的帮助