Erlang/OTP Forums

Author Message

<  Erlyweb mailing list  ~  Implementing before_save/1

Guest
Posted: Thu Dec 27, 2007 4:32 pm Reply with quote
Guest
Do I need to do anything special in my module definition to get ErlyDb
to use my custom before_save/1 implementation? I'm using erlyweb 0.6.2
and the function doesn't get called when I save the record:

6> U = user:new_with([{first_name, "foo"}, {last_name, "bar"},
{password, "abcdef"}, {userid, "fbar"}]).
{user,true,undefined,"foo","bar","fbar","abcdef",undefined}
7> U1 = user:save(U).
{user,false,24,"foo","bar","fbar","abcdef",undefined}
8> U1.
{user,false,24,"foo","bar","fbar","abcdef",undefined}
9> q().

The user module looks like this:

-module(user).

-export([relations/0, before_save/1]).

relations() ->
[{one_to_many, [email_address]}].

before_save(Me) ->
io:format("before_save/1 called~n").

Pointers? Ideas?

Thanks,
Kevin

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Fri Dec 28, 2007 1:30 am Reply with quote
Guest
Tried this with 0.7 and am still seeing the same problem.

--Kevin
On Dec 27, 2007, at 11:30 AM, Kevin A. Smith wrote:

>
> Do I need to do anything special in my module definition to get ErlyDb
> to use my custom before_save/1 implementation? I'm using erlyweb 0.6.2
> and the function doesn't get called when I save the record:
>
> 6> U = user:new_with([{first_name, "foo"}, {last_name, "bar"},
> {password, "abcdef"}, {userid, "fbar"}]).
> {user,true,undefined,"foo","bar","fbar","abcdef",undefined}
> 7> U1 = user:save(U).
> {user,false,24,"foo","bar","fbar","abcdef",undefined}
> 8> U1.
> {user,false,24,"foo","bar","fbar","abcdef",undefined}
> 9> q().
>
> The user module looks like this:
>
> -module(user).
>
> -export([relations/0, before_save/1]).
>
> relations() ->
> [{one_to_many, [email_address]}].
>
> before_save(Me) ->
> io:format("before_save/1 called~n").
>
> Pointers? Ideas?
>
> Thanks,
> Kevin
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Fri Dec 28, 2007 4:35 pm Reply with quote
Guest
Imagine my chagrin when I saw this line in the output of
user:module_info():

{source,"/ldisk/daily_build/otp_prebuild_r12b.2007-12-04_15/
otp_src_R12B-0/lib/kernel/src/user.erl"}

I'm guessing it would be helpful to _not_ use a module name which
clashes with the OTP provided modules. Smile

I was thinking about cooking up a patch to emit a warning message when
erlydb tries to process a builtin class like this one. Would this be
useful to anyone else?

--Kevin
On Dec 27, 2007, at 8:29 PM, Kevin A. Smith wrote:

>
> Tried this with 0.7 and am still seeing the same problem.
>
> --Kevin
> On Dec 27, 2007, at 11:30 AM, Kevin A. Smith wrote:
>
>>
>> Do I need to do anything special in my module definition to get
>> ErlyDb
>> to use my custom before_save/1 implementation? I'm using erlyweb
>> 0.6.2
>> and the function doesn't get called when I save the record:
>>
>> 6> U = user:new_with([{first_name, "foo"}, {last_name, "bar"},
>> {password, "abcdef"}, {userid, "fbar"}]).
>> {user,true,undefined,"foo","bar","fbar","abcdef",undefined}
>> 7> U1 = user:save(U).
>> {user,false,24,"foo","bar","fbar","abcdef",undefined}
>> 8> U1.
>> {user,false,24,"foo","bar","fbar","abcdef",undefined}
>> 9> q().
>>
>> The user module looks like this:
>>
>> -module(user).
>>
>> -export([relations/0, before_save/1]).
>>
>> relations() ->
>> [{one_to_many, [email_address]}].
>>
>> before_save(Me) ->
>> io:format("before_save/1 called~n").
>>
>> Pointers? Ideas?
>>
>> Thanks,
>> Kevin
>>
>>>
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Fri Dec 28, 2007 5:47 pm Reply with quote
Guest
Yes, definitely. I think ErlyDB should just crash when it tries to
compile a module called 'user' because a few people have ran into
this.

On Dec 28, 2007 8:34 AM, Kevin A. Smith <kevin@hypotheticalabs.com> wrote:
>
> Imagine my chagrin when I saw this line in the output of
> user:module_info():
>
> {source,"/ldisk/daily_build/otp_prebuild_r12b.2007-12-04_15/
> otp_src_R12B-0/lib/kernel/src/user.erl"}
>
> I'm guessing it would be helpful to _not_ use a module name which
> clashes with the OTP provided modules. Smile
>
> I was thinking about cooking up a patch to emit a warning message when
> erlydb tries to process a builtin class like this one. Would this be
> useful to anyone else?
>
> --Kevin
>
> On Dec 27, 2007, at 8:29 PM, Kevin A. Smith wrote:
>
> >
> > Tried this with 0.7 and am still seeing the same problem.
> >
> > --Kevin
> > On Dec 27, 2007, at 11:30 AM, Kevin A. Smith wrote:
> >
> >>
> >> Do I need to do anything special in my module definition to get
> >> ErlyDb
> >> to use my custom before_save/1 implementation? I'm using erlyweb
> >> 0.6.2
> >> and the function doesn't get called when I save the record:
> >>
> >> 6> U = user:new_with([{first_name, "foo"}, {last_name, "bar"},
> >> {password, "abcdef"}, {userid, "fbar"}]).
> >> {user,true,undefined,"foo","bar","fbar","abcdef",undefined}
> >> 7> U1 = user:save(U).
> >> {user,false,24,"foo","bar","fbar","abcdef",undefined}
> >> 8> U1.
> >> {user,false,24,"foo","bar","fbar","abcdef",undefined}
> >> 9> q().
> >>
> >> The user module looks like this:
> >>
> >> -module(user).
> >>
> >> -export([relations/0, before_save/1]).
> >>
> >> relations() ->
> >> [{one_to_many, [email_address]}].
> >>
> >> before_save(Me) ->
> >> io:format("before_save/1 called~n").
> >>
> >> Pointers? Ideas?
> >>
> >> Thanks,
> >> Kevin
> >>
> >>>
> >
> >
> > >
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Fri Dec 28, 2007 7:25 pm Reply with quote
Guest
Hmm...when I ran into this problem, a warning message *was* emitted
when erlyweb tried to load user.erl. The warning mentions that "user"
is a "sticky directory."

It will happen with other modules as well:
http://osdir.com/ml/lang.erlang.general/2002-10/msg00100.html

Maybe the warning should be a little louder, but it seems like the
hook is there already.

-Bryan

On Dec 28, 12:46 pm, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
> Yes, definitely. I think ErlyDB should just crash when it tries to
> compile a module called 'user' because a few people have ran into
> this.
>
> On Dec 28, 2007 8:34 AM, Kevin A. Smith <ke...@hypotheticalabs.com> wrote:
> > I was thinking about cooking up a patch to emit a warning message when
> > erlydb tries to process a builtin class like this one. Would this be
> > useful to anyone else?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Fri Dec 28, 2007 7:29 pm Reply with quote
Guest
Here's a patch implementing my try at this. I added a
get_module_compile_path() to smerl to extract a given module's compile
path from it's module_info(). I also added logic to erlydb to inspect
this path and reject any classes which the string "/otp_src_R" in
their path:

1> test_util:start_erlydb("foo", "foo", "foo", "localhost", [user]).

--- To skip foreign key checks, compile with the {skip_fk_checks,
true} option


** exception exit: {extending_system_module,{{module,user},
{compile_path,"/ldisk/
daily_build/otp_prebuild_r12b.2007-12-04_15/otp_src_R12B-0/lib/kernel/
src/user.erl"}}}

If there's a better way to do it, let me know and I'll take another
crack at it.

--Kevin


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---



Post recived from mailinglist
Guest
Posted: Fri Dec 28, 2007 7:36 pm Reply with quote
Guest
I imagine if I was using the framework in a more orthodox way, I'd
probably get that error too. I'm trying to use erlydb outside of
erlyweb proper to implement a couple of gen_servers. I was probably
masking the problem by calling code:unstick_dir("./ebin") but I can't
see any other way around the problem since erlydb wants to modify the
modules at runtime.

I'm thinking about tweaking erlydb to be more compile-time friendly
and save the generated modules to files. I know the guts to support
this already exist but it looks like they just need to be tied
together and surfaced in a friendly way.

--Kevin
On Dec 28, 2007, at 2:25 PM, Bryan Fink wrote:

>
> Hmm...when I ran into this problem, a warning message *was* emitted
> when erlyweb tried to load user.erl. The warning mentions that "user"
> is a "sticky directory."
>
> It will happen with other modules as well:
> http://osdir.com/ml/lang.erlang.general/2002-10/msg00100.html
>
> Maybe the warning should be a little louder, but it seems like the
> hook is there already.
>
> -Bryan
>
> On Dec 28, 12:46 pm, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
>> Yes, definitely. I think ErlyDB should just crash when it tries to
>> compile a module called 'user' because a few people have ran into
>> this.
>>
>> On Dec 28, 2007 8:34 AM, Kevin A. Smith <ke...@hypotheticalabs.com>
>> wrote:
>>> I was thinking about cooking up a patch to emit a warning message
>>> when
>>> erlydb tries to process a builtin class like this one. Would this be
>>> useful to anyone else?
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Sun Dec 30, 2007 6:18 am Reply with quote
Guest
Cool, thanks!

On Dec 28, 2007 11:28 AM, Kevin A. Smith <kevin@hypotheticalabs.com> wrote:
> Here's a patch implementing my try at this. I added a
> get_module_compile_path() to smerl to extract a given module's compile
> path from it's module_info(). I also added logic to erlydb to inspect
> this path and reject any classes which the string "/otp_src_R" in
> their path:
>
> 1> test_util:start_erlydb("foo", "foo", "foo", "localhost", [user]).
>
> --- To skip foreign key checks, compile with the {skip_fk_checks,
> true} option
>
>
> ** exception exit: {extending_system_module,{{module,user},
> {compile_path,"/ldisk/
> daily_build/otp_prebuild_r12b.2007-12-04_15/otp_src_R12B-0/lib/kernel/
> src/user.erl"}}}
>
> If there's a better way to do it, let me know and I'll take another
> crack at it.
>
> --Kevin
>
>
>
> >
>
>
> On Dec 28, 2007, at 12:46 PM, Yariv Sadan wrote:
>
> >
> > Yes, definitely. I think ErlyDB should just crash when it tries to
> > compile a module called 'user' because a few people have ran into
> > this.
> >
> > On Dec 28, 2007 8:34 AM, Kevin A. Smith <kevin@hypotheticalabs.com>
> > wrote:
> >>
> >> Imagine my chagrin when I saw this line in the output of
> >> user:module_info():
> >>
> >> {source,"/ldisk/daily_build/otp_prebuild_r12b.2007-12-04_15/
> >> otp_src_R12B-0/lib/kernel/src/user.erl"}
> >>
> >> I'm guessing it would be helpful to _not_ use a module name which
> >> clashes with the OTP provided modules. Smile
> >>
> >> I was thinking about cooking up a patch to emit a warning message
> >> when
> >> erlydb tries to process a builtin class like this one. Would this be
> >> useful to anyone else?
> >>
> >> --Kevin
> >>
> >> On Dec 27, 2007, at 8:29 PM, Kevin A. Smith wrote:
> >>
> >>>
> >>> Tried this with 0.7 and am still seeing the same problem.
> >>>
> >>> --Kevin
> >>> On Dec 27, 2007, at 11:30 AM, Kevin A. Smith wrote:
> >>>
> >>>>
> >>>> Do I need to do anything special in my module definition to get
> >>>> ErlyDb
> >>>> to use my custom before_save/1 implementation? I'm using erlyweb
> >>>> 0.6.2
> >>>> and the function doesn't get called when I save the record:
> >>>>
> >>>> 6> U = user:new_with([{first_name, "foo"}, {last_name, "bar"},
> >>>> {password, "abcdef"}, {userid, "fbar"}]).
> >>>> {user,true,undefined,"foo","bar","fbar","abcdef",undefined}
> >>>> 7> U1 = user:save(U).
> >>>> {user,false,24,"foo","bar","fbar","abcdef",undefined}
> >>>> 8> U1.
> >>>> {user,false,24,"foo","bar","fbar","abcdef",undefined}
> >>>> 9> q().
> >>>>
> >>>> The user module looks like this:
> >>>>
> >>>> -module(user).
> >>>>
> >>>> -export([relations/0, before_save/1]).
> >>>>
> >>>> relations() ->
> >>>> [{one_to_many, [email_address]}].
> >>>>
> >>>> before_save(Me) ->
> >>>> io:format("before_save/1 called~n").
> >>>>
> >>>> Pointers? Ideas?
> >>>>
> >>>> Thanks,
> >>>> Kevin
> >>>>
> >>>>>
> >>>
> >>>
> >>>>
> >>
> >>
> >>>
> >>
> >
> > --~--~---------~--~----~------------~-------~--~----~
> > You received this message because you are subscribed to the Google
> > Groups "erlyweb" group.
> > To post to this group, send email to erlyweb@googlegroups.com
> > To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
> > For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
> > -~----------~----~----~----~------~----~------~--~---
> >
>
>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Sun Dec 30, 2007 6:20 am Reply with quote
Guest
To specify the output directory for ErlyDB compilation, include the
"outdir" option in the option list. For more info, check out the
documentation for the 'compile' module in the Erlang docs. ErlyDB (and
Smerl) passes all the options it receives all the way down to
'compile:file'.

On Dec 28, 2007 11:33 AM, Kevin A. Smith <kevin@hypotheticalabs.com> wrote:
>
> I imagine if I was using the framework in a more orthodox way, I'd
> probably get that error too. I'm trying to use erlydb outside of
> erlyweb proper to implement a couple of gen_servers. I was probably
> masking the problem by calling code:unstick_dir("./ebin") but I can't
> see any other way around the problem since erlydb wants to modify the
> modules at runtime.
>
> I'm thinking about tweaking erlydb to be more compile-time friendly
> and save the generated modules to files. I know the guts to support
> this already exist but it looks like they just need to be tied
> together and surfaced in a friendly way.
>
> --Kevin
>
> On Dec 28, 2007, at 2:25 PM, Bryan Fink wrote:
>
> >
> > Hmm...when I ran into this problem, a warning message *was* emitted
> > when erlyweb tried to load user.erl. The warning mentions that "user"
> > is a "sticky directory."
> >
> > It will happen with other modules as well:
> > http://osdir.com/ml/lang.erlang.general/2002-10/msg00100.html
> >
> > Maybe the warning should be a little louder, but it seems like the
> > hook is there already.
> >
> > -Bryan
> >
> > On Dec 28, 12:46 pm, "Yariv Sadan" <yarivsa...@gmail.com> wrote:
> >> Yes, definitely. I think ErlyDB should just crash when it tries to
> >> compile a module called 'user' because a few people have ran into
> >> this.
> >>
> >> On Dec 28, 2007 8:34 AM, Kevin A. Smith <ke...@hypotheticalabs.com>
> >> wrote:
> >>> I was thinking about cooking up a patch to emit a warning message
> >>> when
> >>> erlydb tries to process a builtin class like this one. Would this be
> >>> useful to anyone else?
> >
> > >
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum