Getting error using 'belongs_to' in Ecto phoenix.gen.html

时间:2015-10-29 15:44:28

标签: elixir phoenix-framework ecto

I'm making an model that I want to create in relationship to my user model. Following from http://www.phoenixframework.org/v0.13.1/docs/ecto-models#section-data-relationship-and-dependencies used the phoenix.gen.html as follows:

W:runcible>mix phoenix.gen.html Ansible ansibles ansible_name:string ansible_description:text user:belongs_to

But I Get the following when i run it.

Compiled web/models/user.ex
Compiled web/controllers/user_controller.ex
Generated runcible app
** (Mix) Unknown type `belongs_to` given to generator

Any ideas where I've made a mistake?

1 个答案:

答案 0 :(得分:11)

You are looking at an old version (0.13) of the documentation.

As of Phoenix 0.16 It should be:

mix phoenix.gen.model Video videos name:string approved_at:datetime description:text likes:integer views:integer user_id:references:users

Note:

user_id:references:users

instead of:

user:belongs_to

Here is a link to the latest docs.