gpt4 book ai didi

ruby-on-rails - rails : is there a way to add associations via the command line?

转载 作者:行者123 更新时间:2023-12-04 13:50:28 26 4
gpt4 key购买 nike

Rails documentation ,我们找到以下示例:

class Physician < ActiveRecord::Base
has_many :appointments
has_many :patients, :through => :appointments
end

我只是好奇:是否可以使用 rails generate model 通过命令行生成它?

最佳答案

不是根据您从 rails generate model 获得的使用消息。不过,您可以设置 belongs_to 关系:

rails generate model photo title:string album:references

app/models/photo.rb 中给我以下内容:

class Photo < ActiveRecord::Base
belongs_to :album
end

关于ruby-on-rails - rails : is there a way to add associations via the command line?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13462163/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com