How to maintain orderly list of records in relationship N:N

Asked

Viewed 45 times

1

Considering a scenario where a author can hold several publications and a publishing may have several authors, we have an intermediate table to maintain relationships.

However, the order of authors in a publishing is chosen by the customer at the time of creating or updating of publishing.

In this case it would be feasible to keep an attribute (e.g., JSON) in the table of publishing to guard the sorted keys of relationships?

How to maintain order in author list?

EXAMPLE OF A CASE

The user 1 calf the publicao1 and relates to it, in addition to it (which is related automatically by being the creator), users: user 2, user 3 and user 4.

However, he wants the authors of this publication to be shown in the following order: user 4, user 1, user 3 and user 2.

Any of the authors may change this order later.

  • you could post the structure of existing tables, and what you want between them !?

  • @Thiagofriedman The structure of the tables is simple: membro | publicacao | membro_publicacao. What I want is described in the question: how can I keep a certain order in the list of authors that are related to a publication?

  • @Dontvotemedown could explain better how to solve using this practice?

  • Forget the sub-query, I was full of shit. Your case I think would have to save the order in the relationship table (intermediate), see: http://sqlfiddle.com/#! 9/f2d256/5

1 answer

2


Just save the order in the relationship table (intermediate), so you know the order for each author of that publication.

Demo

Browser other questions tagged

You are not signed in. Login or sign up in order to post.