以编程方式调用 active_record 生成器:如何传递父参数?

发布于 2024-11-25 21:14:53 字数 576 浏览 1 评论 0原文

在所有这些情况下,父参数都会被忽略:

Rails::Generators.invoke("active_record:model", [name, ["list_order:string", "name:string"], ["parent=Ecm::Toplist::Base"]])
Rails::Generators.invoke("active_record:model", [name, ["list_order:string", "name:string"], ["--parent=Ecm::Toplist::Base"]])
Rails::Generators.invoke("active_record:model", [name, ["list_order:string", "name:string"], "parent=Ecm::Toplist::Base"])
Rails::Generators.invoke("active_record:model", [name, ["list_order:string", "name:string"], "--parent=Ecm::Toplist::Base"])

这是一个错误,还是我遗漏了什么?

The parent argument is ignored, in all of these cases:

Rails::Generators.invoke("active_record:model", [name, ["list_order:string", "name:string"], ["parent=Ecm::Toplist::Base"]])
Rails::Generators.invoke("active_record:model", [name, ["list_order:string", "name:string"], ["--parent=Ecm::Toplist::Base"]])
Rails::Generators.invoke("active_record:model", [name, ["list_order:string", "name:string"], "parent=Ecm::Toplist::Base"])
Rails::Generators.invoke("active_record:model", [name, ["list_order:string", "name:string"], "--parent=Ecm::Toplist::Base"])

Is this a bug, or am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

菩提树下叶撕阳。 2024-12-02 21:14:53

正确的方法是

Rails::Generators.invoke("active_record:model", [name, "list_order:string", "name:string"], { parent: "Ecm::Toplist::Base"})

但是要小心,根据 this 一旦指定:parent,迁移将不会被调用。

通过迁移生成模型的正确方法是

Rails::Generators.invoke("active_record:model", [name, "list_order:string", "name:string"], {migration: true, timestamps: true})

Correct way will be

Rails::Generators.invoke("active_record:model", [name, "list_order:string", "name:string"], { parent: "Ecm::Toplist::Base"})

But be careful, according to this once you specify :parent, the migration will not be invoked.

The correct way to generate model with migration will be

Rails::Generators.invoke("active_record:model", [name, "list_order:string", "name:string"], {migration: true, timestamps: true})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文