Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.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 Rails:有没有办法通过命令行添加关联?_Ruby On Rails_Command Line_Model - Fatal编程技术网

Ruby on rails Rails:有没有办法通过命令行添加关联?

Ruby on rails Rails:有没有办法通过命令行添加关联?,ruby-on-rails,command-line,model,Ruby On Rails,Command Line,Model,在中,我们发现以下示例: class Physician < ActiveRecord::Base has_many :appointments has_many :patients, :through => :appointments end class医生:预约 结束 我只是好奇:是否可以使用railsgeneratemodel通过命令行生成此文件?而不是根据从railsgeneratemodel获得的用法消息。您可以设置属于关系,但: rails generate

在中,我们发现以下示例:

class Physician < ActiveRecord::Base
  has_many :appointments
  has_many :patients, :through => :appointments
end
class医生:预约
结束

我只是好奇:是否可以使用
railsgeneratemodel
通过命令行生成此文件?

而不是根据从
railsgeneratemodel
获得的用法消息。您可以设置属于关系,但:

rails generate model photo title:string album:references
app/models/photo.rb中提供以下信息:

class Photo < ActiveRecord::Base
  belongs_to :album
end
class-Photo
不是根据您从
rails generate model
获得的用法消息。您可以设置属于
关系,但:

rails generate model photo title:string album:references
app/models/photo.rb中提供以下信息:

class Photo < ActiveRecord::Base
  belongs_to :album
end
class-Photo
谢谢。因此,我是否仍然可以使用
generate
命令,然后在迁移之前通过手动关联添加
has\u many
?自动生成的迁移文件中是否有需要更改的内容?没有。由于
有许多
,外键在另一个表中。您只需在执行
属于
关系时添加一列即可。谢谢。因此,我是否仍然可以使用
generate
命令,然后在迁移之前通过手动关联添加
has\u many
?自动生成的迁移文件中是否有需要更改的内容?没有。由于
有许多
,外键在另一个表中。您只需要在执行
属于
关系时添加一列。