multiple relations from one table to another

165 views
Skip to first unread message

Sigma

unread,
Feb 27, 2012, 5:22:48 PM2/27/12
to NotORM
Hello there.

I checkout NotORM, which is a very interesting project, I think. In my
schema I have two tables with two relations to eachother. How do I
handle this?

table: article
columns: id, title, text, publisher_id (referencing user), author_id
(referencing user)

table: user
columns: id, name

How can I achieve to get from an acticle row to a publisher user and
to a author user row?

I would really appreciate your help.

Regards,
Sigma

Martin Kopeček

unread,
Sep 18, 2012, 5:33:02 AM9/18/12
to not...@googlegroups.com, steff....@googlemail.com
I'm having the same problem, have you solved yours by now?

Tables:
events (ID,name,date, description,author,organizator1,organizator2)
users (ID,name,email)

Problem:
How do I get names of organizators for a specific event? Since there are more relationships, I cannot use the conventional $event->users["email"]. I might use NotORM_Structure to define dummy tables, that link events and users the right way (e.g. if table=organizators2, then join tables events and users using organizator2), but that seems to me as an ugly solution.

Thanks,
Martin Kopeček

Karel Borkovec

unread,
Sep 29, 2012, 7:54:57 AM9/29/12
to not...@googlegroups.com, steff....@googlemail.com
I think that subclassing NotORM_Structure is the only solution.

Dne úterý, 18. září 2012 11:33:02 UTC+2 Martin Kopeček napsal(a):

Jakub Vrana

unread,
Dec 21, 2013, 9:23:35 AM12/21/13
to not...@googlegroups.com, steff....@googlemail.com
Yeah, you have to extend Convention or use NotORM_Structure_Discovery.

If you are trying to access related data of a one row only then you can
also use:

$db->user[$article['author_id']]

But don't do this in a loop as it will execute a query every time.

Jakub

On 09/29/2012 04:54 AM, Karel Borkovec wrote:
> I think that subclassing NotORM_Structure is the only solution.
>
> Dne úterý, 18. září 2012 11:33:02 UTC+2 Martin Kopeček napsal(a):
>
> I'm having the same problem, have you solved yours by now?
>
> *Tables:*
> events (ID,name,date, description,author,organizator1,organizator2)
> users (ID,name,email)
>
> *Problem:*
> How do I get names of organizators for a specific event? Since there
> are more relationships, I cannot use the conventional
> $event->users["email"]. I might use NotORM_Structure to define dummy
> tables, that link events and users the right way (e.g. if
> table=/organizators2/, then join tables /events /and /users /using
> /organizator2/), but that seems to me as an ugly solution.
Reply all
Reply to author
Forward
0 new messages