model:attributes(). error

121 views
Skip to first unread message

rastin rastini

unread,
May 6, 2014, 11:25:54 PM5/6/14
to chica...@googlegroups.com
hi all
when i use Model:attributes(). or Model:id().
then get this error:
"exception error: bad argument
     in function  apply/3
        called as apply([{master,"master-1",<<"my name field">>,<<"this is address field">>,
                                 <<"description field">>}],
                        id,[])
"
my db is postgresql.
thankfull

Graeme Defty

unread,
May 6, 2014, 11:51:35 PM5/6/14
to chica...@googlegroups.com
Looks like the model has not been recognised.

What do you have in your model code?




--
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/6bd1bb29-c3ad-4d1d-bed0-c5fcc4ba5f43%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

rastin rastini

unread,
May 9, 2014, 12:52:47 AM5/9/14
to chica...@googlegroups.com
my model is:
-module(master, [Id, Name, Address, Description]).
-compile(export_all).


my table is postgresql scheme:
id          | integer                | not null default nextval('masters_id_seq'::regclass) | plain    |              |
 name        | character varying(50)  |                                                      | extended |              |
 address     | character varying(100) |                                                      | extended |              |
 description | character varying      |                                                      | extended |              |
Indexes:
    "masters_pkey" PRIMARY KEY, btree (id)
Referenced by:
    TABLE "resumes" CONSTRAINT "resumes_masterid_fkey" FOREIGN KEY (masterid) REFERENCES masters(id)
Has OIDs: no

rastin rastini

unread,
May 9, 2014, 10:34:39 PM5/9/14
to chica...@googlegroups.com
any one can help?

Ángel Herranz

unread,
May 10, 2014, 1:02:17 PM5/10/14
to chica...@googlegroups.com
I think Model contain a list with a unique master record instead of a master record. Could be?

El sábado, 10 de mayo de 2014 04:34:39 UTC+2, rastin rastini escribió:
any one can help?

can2nac

unread,
May 10, 2014, 2:31:18 PM5/10/14
to chica...@googlegroups.com
show code where u create instance and the whole error log, in partuclar to what moule apply belongs? 

rastin rastini

unread,
May 10, 2014, 10:01:56 PM5/10/14
to chica...@googlegroups.com
model is master. in another table we have reference key to this table.
when i use this command in shell got error:
"Master1:set(name, <<"n1">>".
this also got error:
"Master1:attributes()."

can2nac

unread,
May 11, 2014, 9:59:47 AM5/11/14
to chica...@googlegroups.com
try 
>> Master1:set([{name,<<"n1">>}].

On Wednesday, May 7, 2014 7:25:54 AM UTC+4, rastin rastini wrote:

rastin rastini

unread,
May 11, 2014, 10:13:17 AM5/11/14
to chica...@googlegroups.com
i do this but go error:
** exception error: bad argument
     in function  apply/3
        called as apply([{master,"master-1",<<"naja">>,<<"tehran">>,
                                 <<"naja master">>}],
                        set,
                        [[{name,<<"name1">>}]])

can2nac

unread,
May 12, 2014, 11:42:30 AM5/12/14
to chica...@googlegroups.com
try Master1:set([{name,"n1"}].

On Wednesday, May 7, 2014 7:25:54 AM UTC+4, rastin rastini wrote:

rastin rastini

unread,
May 13, 2014, 5:22:17 AM5/13/14
to chica...@googlegroups.com
i do this but got error.
pls see that when i use "Master1:attributes()." got error too.

David Welton

unread,
May 13, 2014, 5:25:07 AM5/13/14
to chica...@googlegroups.com
Which version of CB are you using?

--
David N. Welton

http://www.welton.it/davidw/

http://www.dedasys.com/

Graeme Defty

unread,
May 13, 2014, 6:22:56 AM5/13/14
to chica...@googlegroups.com
Hmmmmm - sounds to me as if your model is not being compiled with the correct compiler/pre-processor/magic.  Not sure if someone asked this already, but you DO have the source in the correct directory, yes? (i.e. the "model" directory)

If so, what do you get on the command line in response to:

   master:module_info(exports).

g



On 13 May 2014 16:22, rastin rastini <program...@gmail.com> wrote:
i do this but got error.
pls see that when i use "Master1:attributes()." got error too.

--
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.

rastin rastini

unread,
May 13, 2014, 8:35:06 AM5/13/14
to chica...@googlegroups.com
my CB version is 0.8.7.
 
when is run command "master:module_info(exports)." then get this out put:

"
[{attribute_names,1},
 {attribute_types,1},
 {database_columns,1},
 {database_table,1},
 {validate_types,1},
 {validate,1},
 {save,1},
 {set,2},
 {set,3},
 {attributes,1},
 {belongs_to_names,1},
 {belongs_to_types,1},
 {belongs_to,1},
 {id,1},
 {name,1},
 {address,1},
 {description,1},
 {get,2},
 {new,4},
 {instance,4},
 {module_info,0},
 {module_info,1}]

"

Ángel Herranz

unread,
May 13, 2014, 10:11:23 AM5/13/14
to chica...@googlegroups.com
Maybe I am wrong but it seems to me that Master is not a boss record but a list.

can2nac

unread,
May 13, 2014, 11:07:46 AM5/13/14
to chica...@googlegroups.com
attach actual model file, do not paste content

can2nac

unread,
May 13, 2014, 11:11:29 AM5/13/14
to chica...@googlegroups.com
also give a full error log as it is not clear in which nodule "apply" is
then one can check that module, check apply function and figure out why exception was given  

@@
"exception error: bad argument
     in function  apply/3
        called as apply([{master,"master-1",<<"my name field">>,<<"this is address field">>,
                                 <<"description field">>}],
                        id,[])
@@

rastin rastini

unread,
May 13, 2014, 11:46:50 AM5/13/14
to chica...@googlegroups.com
model file is attached.

this is an work flow:

1>boss_db:find(master, []).

[{master,"master-1",<<"naja">>,<<"tehran">>,
         <<"naja master">>},
 {master,"master-2",<<"artesh">>,<<"tehran">>,
         <<"artesh master">>}]


2> Master1= boss_db:find(master, [{id, 'equals', "master-1"}]).

[{master,"master-1",<<"naja">>,<<"tehran">>,
         <<"naja master">>}]

3> Master1:attributes().
** exception error: bad argument
     in function  apply/3

        called as apply([{master,"master-1",<<"naja">>,<<"tehran">>,
                                 <<"naja master">>}],
                        attributes,[])

master.erl

David Welton

unread,
May 13, 2014, 11:52:34 AM5/13/14
to chica...@googlegroups.com
> 1>boss_db:find(master, []).
>
> [{master,"master-1",<<"naja">>,<<"tehran">>,
> <<"naja master">>},
> {master,"master-2",<<"artesh">>,<<"tehran">>,
> <<"artesh master">>}]

This returned a list with two elements.

> 2> Master1= boss_db:find(master, [{id, 'equals', "master-1"}]).
>
> [{master,"master-1",<<"naja">>,<<"tehran">>,
> <<"naja master">>}]

This returned a *list* with one element. Ángel Herranz was correct!

What you probably want is:

[Master1] = boss_db:find(master, [{id, 'equals', "master-1"}]).

> 3> Master1:attributes().
> ** exception error: bad argument
> in function apply/3
>
> called as apply([{master,"master-1",<<"naja">>,<<"tehran">>,
> <<"naja master">>}],
> attributes,[])

And this does not work with a list as the argument!

Jesse Gumm

unread,
May 13, 2014, 11:53:21 AM5/13/14
to chica...@googlegroups.com

There the problem. find returns a list of elements, not a single element. So Master1 is a list of elements.

Do

[Master1] = boss_db:find(master, [{id, 'equals', "master-1"}]).

Then your attributes call should work.

-Jesse

--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

--
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.

Jesse Gumm

unread,
May 13, 2014, 11:54:59 AM5/13/14
to chica...@googlegroups.com

Err David beat me to it.

I also did [Master1] in my haste and should have done something like [Master1 | _]

--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com || @jessegumm

Graeme Defty

unread,
May 13, 2014, 11:55:33 AM5/13/14
to chica...@googlegroups.com
WARNING!    IAMAEE  (I Am Not An Erlang Expert)  what follows is based on long hours of debugging similar issues in CB (not through long and thoughtful studies of CB internals) and may be inaccurate, inefficient or at least wildly wrong.

With that out of the way, I THINK what is happening is the following:

'apply' here is the erlang BIF (http://www.erlang.org/doc/man/erlang.html#apply-2)

It is being used to evaluate the call because the Master variable has not been recognised as a CB model.

The output from the module_info function shows that it has been compiled correctly (attributes, set, etc functions are present) so the remaining possibility that I have personally encountered is that the erlang record is the wrong length. However, looking at the model code originally provided

     -module(master, [Id, Name, Address, Description]).
     -compile(export_all).

and the record provided in the error message:


     {master,"master-1",<<"my name field">>,<<"this is address field">>,<<"description field">>},

things seem to line up fine

So the only thing I can see that is 'odd' in my experience is the values in the fields. I always use string values, which may have been an original constraint of CB. If it was, it certainly has been relaxed now, the documentation clearly says binaries are allowed. Maybe someone with experience in PostgreSQL/CB may be able to correct me (I use Mnesia only) but it may be worth trying the same thing with the record:

     {master,"master-1","my name field","this is address field","description field"}

and see what happens. Possibly you need to have typing info in the model for it to work with PostgreSQL?

(Yes, I am clutching at straws here a bit, but I seem to have lost my boat :-( )

g



--
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.

rastin rastini

unread,
May 13, 2014, 11:55:54 AM5/13/14
to chica...@googlegroups.com
oh. very thx to all of you.

David Welton

unread,
May 13, 2014, 12:03:45 PM5/13/14
to chica...@googlegroups.com
> I also did [Master1] in my haste and should have done something like
> [Master1 | _]

Why, out of curiosity? My reasoning would be: it's supposed to return
one element, and if it doesn't, something is wrong.

Jesse Gumm

unread,
May 13, 2014, 12:09:31 PM5/13/14
to chica...@googlegroups.com
Yeah, you're right. Sorry, I'm still a bit groggy, and answering
questions on my phone in bed is not a great way to troubleshoot.

I was transposing the first query with the second query, and thinking
he had two elements being returned.

Caffeine time for me.
> --
> 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/CA%2Bb9R_thMbtG5m_am-J9OG7nys96TqxDd5Qzzv4mV2_fUeUM0w%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



can2nac

unread,
May 14, 2014, 10:10:54 AM5/14/14
to chica...@googlegroups.com
Master1 = boss_db:find("master-1").

in case options are required

Master2 = boss_db:find_first(master, [{id, 'equals', "master-1"},{option 1},{option 2}]).

well, you could have saved a lot of yours and your's time if you would have sent us all that data from the very beginning as i told you))))

can2nac

unread,
May 14, 2014, 10:15:05 AM5/14/14
to chica...@googlegroups.com
*yours and our's
Reply all
Reply to author
Forward
0 new messages