pop icon indicating copy to clipboard operation
pop copied to clipboard

Idea: ordering in join tables

Open arschles opened this issue 6 years ago • 1 comments

Would it make sense to add support for ordering in a join table? Here's a rough idea on how that could be achieved. If this was the model:

type User struct {
    Books Books `many_to_many:"user_books"`
}

... and this was the migration:

create_table("books", func(t) {})
create_table("user_books", func(t) {
    t.Column("book_id", "uuid", {})
    t.Column("user_id", "uuid", {})
    t.Column("ordering", int, {})
})

Pop could look for whether Books implements sort.Interface, do the sort before saving, and populate the ordering column appropriately. When someone does an eager query, pop can sort the resulting Books according to ordering

Technically I think this could be done above pop but then you'd have to manage the join table manually.

Thoughts?

arschles avatar Apr 18 '18 20:04 arschles

I don't think this should be part of pop. Users can order themselves easily.

petar-dambovaliev avatar May 20 '18 17:05 petar-dambovaliev