H
H
Holmess882021-04-17 11:13:31
SQL
Holmess88, 2021-04-17 11:13:31

How to set an increment on a column that will be the sort order of the records of another non-unique column of this table?

Hello!
There is a table with a composite key:
1) a link to the parent model from another table
2) the ordinal number of the child model in the parent.

Question:
How to transfer to the database layer through the migration constructor the increment of the child model's ordinal number relative to the parent model, and not the table as a whole? At the same time, it should be possible to change the order of child models.

Tools: Laravel 8.0 + Eloquent

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-04-17
@Rsa97

By and large, for sorting the records of the child model, the ordinal number of the child record inside the parent is not important, only the increase of a certain attribute is important.
That is, if you have an auto-increment field in your child model, then sorting child records by it will give the order in which they were added, and it doesn’t matter that in this field (10, 17, 35, 1221), and not (1, 2, 3, 4).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question