postgresql and relationship between models

41 views
Skip to first unread message

David Jacobs

unread,
Feb 28, 2015, 2:45:19 PM2/28/15
to chica...@googlegroups.com
Hi,

I need an example of a relationship between two models and how the migration tables need to be for postgresql.

I want to model roles and users which can all have one and only one role.

role.erl:

-module(role, [Id, Role_short, Role_long]).
-compile(export_all).

migration:

  CREATE TABLE roles(
      id serial unique
   
, role_short text not null
   
, role_long text not null
 
);


user.erl

-module(user, [Id, Name, Vpe, RoleId]).
-compile(export_all).

migration:

  CREATE TABLE users(
      id SERIAL UNIQUE PRIMARY KEY
   
, name text not null
   
, vpe text
   
, roleid integer not null
 
);


Everything compiles, tables are created on db. But when I go to admin-page and continue to model user, then there's an error (listed below). I guess line 4 gives the most detail: "bad arithmetic expression in boss_record_lib:dummy_record/1"?

What do I need to adjust? I tried several different variations - but no success.

Thanks in advance!
david

error from console.log:
2015-02-28 20:37:23.007 [info] <0.308.0> Route: "/model/model/user"Url
[]
2015-02-28 20:37:23.009 [notice] <0.308.0>@boss_controller_adapter_pmod:action:91 Request Method: 'GET', Tokens: ["user"]
2015-02-28 20:37:23.009 [error] <0.295.0> gen_server <0.295.0> terminated with reason: bad arithmetic expression in boss_record_lib:dummy_record/1 line 76
2015-02-28 20:37:23.010 [error] <0.295.0> CRASH REPORT Process <0.295.0> with 1 neighbours exited with reason: bad arithmetic expression in boss_record_lib:dummy_record/1 line 76 in gen_server:terminate/7 line 804
2015-02-28 20:37:23.010 [error] <0.98.0> Supervisor {<0.98.0>,poolboy_sup} had child boss_db_controller started with {boss_db_controller,start_link,undefined} at <0.295.0> exit with reason bad arithmetic expression in boss_record_lib:dummy_record/1 line 76 in context child_terminated
2015-02-28 20:37:23.014 [error] <0.308.0>@boss_web_controller:call_controller_action:319 Error in controller exit:{{badarith,
          [{boss_record_lib,dummy_record,1,
               [{file,"src/boss_record_lib.erl"},{line,76}]},
           {boss_record_lib,database_columns,1,
               [{file,"src/boss_record_lib.erl"},{line,93}]},
           {boss_db_adapter_pgsql,build_conditions,2,
               [{file,"src/db_adapters/boss_db_adapter_pgsql.erl"},
                {line,337}]},
           {boss_db_adapter_pgsql,count,3,
               [{file,"src/db_adapters/boss_db_adapter_pgsql.erl"},{line,76}]},
           {boss_db_controller,handle_call,3,
               [{file,"src/boss_db_controller.erl"},{line,138}]},
           {gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,607}]},
           {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,639}]},
           {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,237}]}]},
      {gen_server,call,[<0.295.0>,{count,user,[]},30000]}} Stacktrace: [{gen_server,call,3,[{file,"gen_server.erl"},{line,190}]},{boss_pool,call,3,[{file,"src/boss_pool.erl"},{line,12}]},{cb_admin_model_controller,model,4,[{file,"/home/david/projects/erlang/cb_admin/src/controller/cb_admin_model_controller.erl"},{line,34}]},{boss_web_controller,call_controller_action,3,[{file,"src/boss/boss_web_controller.erl"},{line,316}]},{boss_web_controller,apply_action,4,[{file,"src/boss/boss_web_controller.erl"},{line,308}]},{boss_web_controller,execute_action_inner,9,[{file,"src/boss/boss_web_controller.erl"},{line,287}]},{boss_web_controller_handle_request,process_dynamic_request,5,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,254}]},{boss_web_controller_handle_request,process_request,5,[{file,"src/boss/boss_web_controller_handle_request.erl"},{line,244}]}]
2015-02-28 20:37:23.017 [error] <0.308.0> Error in controller, see console.log for details

2015-02-28 20:37:23.017 [error] <0.308.0> GET /admin/model/model/user [cb_admin] 500 0ms




Kai Janson

unread,
Feb 28, 2015, 6:14:33 PM2/28/15
to chica...@googlegroups.com
Shouldn't that be role_id in the table?

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "ChicagoBoss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chicagoboss...@googlegroups.com.
Visit this group at http://groups.google.com/group/chicagoboss.
To view this discussion on the web visit https://groups.google.com/d/msgid/chicagoboss/af0a1c1f-275a-425d-bdc6-0b0d0327c364%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Jacobs

unread,
Mar 1, 2015, 2:24:31 PM3/1/15
to chica...@googlegroups.com
Hi,

That change roleid -> role_id didn't do much at first. But I changed the naming from user to something else. Now everything seems to work.

Is there any information on the naming conventions?

Now experimenting with belongs_to & has...

Kind regards,
david

Op zondag 1 maart 2015 00:14:33 UTC+1 schreef Kai Janson:

Graeme Defty

unread,
Mar 1, 2015, 6:58:54 PM3/1/15
to chica...@googlegroups.com

This is an issue which pops up from time to time. 

The name  "user"  is reserver somewhere in the Erlang ecosystem and therefore unavailable for our use :-(



David Jacobs

unread,
Mar 3, 2015, 8:28:33 AM3/3/15
to chica...@googlegroups.com
Hi,

Okay, the user-restriction is one part of the naming convention. That helped!

I was also thinking about the mapping between modeldefinition in ./src/model/role.erl <-> table- and column-names in db (eg. postgresql).

Thanks,
david

--
You received this message because you are subscribed to a topic in the Google Groups "ChicagoBoss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/chicagoboss/Y9KKPC1h_6E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to chicagoboss...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages