如何使用Ember-cli生成带有属性的模型(包括关系)?

时间:2017-02-24 02:00:20

标签: ember.js ember-cli

我记得有一种方法可以生成一个模型,其中包含使用ember-cli的模型的所有属性和关系,如下所示

ember g model user name:string email:string user:has-many

这样我就可以避免一次又一次地输入所有attr

name: DS.attr('string')

但是我找不到任何关于它的参考。我在哪里可以找到更多参考。关于如何使用attritbues和关系生成模型的详细用法?

问题

在哪里可以找到命令option的详细ember generate <generator-name> <options>参考?

1 个答案:

答案 0 :(得分:0)

我找到了以下帮助信息。使用

ember help generate model

参考,https://github.com/ember-cli/ember-cli/pull/3316

Requested ember-cli commands:

ember generate <blueprint> <options...>
  Generates new code from blueprints.
  aliases: g
  --dry-run (Boolean) (Default: false)
    aliases: -d
  --verbose (Boolean) (Default: false)
    aliases: -v
  --pod (Boolean) (Default: false)
    aliases: -p
  --classic (Boolean) (Default: false)
    aliases: -c
  --dummy (Boolean) (Default: false)
    aliases: -dum, -id
  --in-repo-addon (String) (Default: null)
    aliases: --in-repo <value>, -ir <value>

      model <name> <attr:type>
        Generates an ember-data model.
        You may generate models with as many attrs as you would like to pass. The following attribute types are supported:
        <attr-name>
        <attr-name>:array
        <attr-name>:boolean
        <attr-name>:date
        <attr-name>:object
        <attr-name>:number
        <attr-name>:string
        <attr-name>:your-custom-transform
        <attr-name>:belongs-to:<model-name>
        <attr-name>:has-many:<model-name>

        For instance: `ember generate model taco filling:belongs-to:protein toppings:has-many:toppings name:string price:number misc`
        would result in the following model:


        import DS from 'ember-data';

        export default DS.Model.extend({
          filling: DS.belongsTo('protein'),
          toppings: DS.hasMany('topping'),
          name: DS.attr('string'),
          price: DS.attr('number'),
          misc: DS.attr()
        });