Hi,
I added in trunk some features to let you override default ErlyDB
relations settings.
In the relations list, each related module can now take the form
{Module::atom(), Options::proplist()} (previously, it was just
Module::atom()). In many-to-one and one-to-many relations, Options may
include any of the following:
{alias, Alias::atom()} : tells ErlyDB to use Alias as the base name
for the generated functions for working with related records from
Module.
{fk_base, Base::atom()} : tells ErlyDB to use Base as the base name
for foreign keys in the database instead of the related table's name.
{foreign_keys, PkFks::[{Pk::atom(), Fk::atom()}]} : tells ErlyDb to
use the specified mappings between primary and foreign keys. This
option overrides fk_base if it exists.
Here's an example:
app.sql:
create table dog(
id integer auto_increment primary key,
name varchar(30),
person_owner_id integer, # foreign key to 'person'
index(owner_id));
create table person(
id integer auto_increment primary key,
name varchar(30));
dog.erl:
-module(dog).
-compile(export_all).
relations() ->
[{many_to_one,
[{person,
[{alias, owner},
{fk_base, person_owner}]}]}]. % this option is equivalent
to "{foreign_keys, [{id, person_owner_id}]}"
person.erl:
-module(person).
-compile(export_all).
relations() ->
[{one_to_many,
[{dog,
[{alias, pet},
{fk_base, person_owner}]}]}]. % this option is equivalent to
"{foreign_keys, [{id, person_owner_id}]}"
After compilation, you should be able to do the following:
D = dog:new(...),
D1 = dog:save(D),
P = person:new(...),
P1 = person:save(P),
D2 = dog:owner(D1, P1),
D3 = dog:save(D2),
person:pets(P1) %% returns [D3]
Many-to-many relations have the following new options:
{alias, Alias::atom()} : Alias is the new name to be used when
generating functions for working with related records
{relation_table, Table::atom()} : Tells ErlyDB to use the specified
table name for the table used to store relations.
These should be self-explanatory.
Please let me know if it's useful to you and if you find any problems.
Thanks,
Yariv
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"erlyweb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---