2009/7/7 Alexander Dergachev <[email protected]>
>
> Hi. If I got it right, then I don't see any problem :)
>
> As I understood the concept of subforums, any forum can have some
> number of subforums, but is it really case one subforum may be placed
> in more them one forum? Do we really need many-to-many relation?
>
> On 7/7/09, Takayoshi Kyou <[email protected]> wrote:
> >
> > Hi all,
> >
> > I am trying to make a forum application that every forum can have
> > their
> > child-forums. But I found it hard to represent these with erlydb.
> >
> > First I tried to use a self-referencing many-to-many relation:
> >
> > new (A) ->
> >     Post_data = yaws_api:parse_post(A),
> >     {value, {parent_forum_id, Parent_forum_id_str}, Other_fields} =
> >       lists:keytake(parent_forum_id, 1,
> >                     %% convert every keys from string to atom
> >                     [ {list_to_atom(K), V} || {K, V} <- Post_data ]),
> >     New_forum = forum:save(forum:new_with(Other_fields)),
> >     Parent_forum_id = list_to_integer(Parent_forum_id_str),
> >     %% A negative parent ID means it is an orphan.
> >     if Parent_forum_id > 0 ->
> >           forum:add_forum( forum:find_id(Parent_forum_id), New_forum );
> >        true ->
> >           ok
> >     end,
> >     {ewr, forum, index}.
> >
> >
> > But this isn't work because the relation between parent and child is
> > "two-way"
> > that I can't detect who is the parent and who are the childern when I
> > use
> > forum:forums to access it.
> >
> > Any idea?
> >
> >
> > Thanks
> > >
> >
>
>
> --
> With Best Regards,
> Alexander Dergachev
>
> >

Oh. Maybe I'm going the wrong way...
Yes, this is only a one-to-many relations that one forum can have many
sub-forums. Is it means I should define a "self-referencing one-to-many
relation"?

But maybe why I think of many-to-many first is that I felt unnatural to write a
self-referencing one-to-many relation.

If table1 have a one-to-many relation to table2, I would say:

-module(table1).
relations () -> {one_to_many, [table2]}.

-module(table2).
relations () -> {many_to_one, [table1]}.

But it's strange to say:
relations () -> [{one_to_many, [forum]}, {many_to_one, [forum]}].

Or maybe I should just use a extra column called parent_forum_id? If I do so,
will it going to be inconvenient to access them (because erlydb won't make
access functions automatically)?


Thanks.

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

Reply via email to