pop
pop copied to clipboard
Idea: ordering in join tables
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?
I don't think this should be part of pop. Users can order themselves easily.