diff --git a/lib/components_elixir/inventory.ex b/lib/components_elixir/inventory.ex index 30c90df..c42f115 100644 --- a/lib/components_elixir/inventory.ex +++ b/lib/components_elixir/inventory.ex @@ -289,16 +289,16 @@ defmodule ComponentsElixir.Inventory do defp apply_component_sorting(query, opts) do case Keyword.get(opts, :sort_criteria, "name_asc") do - "name_asc" -> order_by(query, [c], asc: c.name) - "name_desc" -> order_by(query, [c], desc: c.name) - "inserted_at_asc" -> order_by(query, [c], asc: c.inserted_at) - "inserted_at_desc" -> order_by(query, [c], desc: c.inserted_at) - "updated_at_asc" -> order_by(query, [c], asc: c.updated_at) - "updated_at_desc" -> order_by(query, [c], desc: c.updated_at) - "count_asc" -> order_by(query, [c], asc: c.count) - "count_desc" -> order_by(query, [c], desc: c.count) + "name_asc" -> order_by(query, [c], [asc: c.name, asc: c.id]) + "name_desc" -> order_by(query, [c], [desc: c.name, asc: c.id]) + "inserted_at_asc" -> order_by(query, [c], [asc: c.inserted_at, asc: c.id]) + "inserted_at_desc" -> order_by(query, [c], [desc: c.inserted_at, asc: c.id]) + "updated_at_asc" -> order_by(query, [c], [asc: c.updated_at, asc: c.id]) + "updated_at_desc" -> order_by(query, [c], [desc: c.updated_at, asc: c.id]) + "count_asc" -> order_by(query, [c], [asc: c.count, asc: c.id]) + "count_desc" -> order_by(query, [c], [desc: c.count, asc: c.id]) # Default fallback - _ -> order_by(query, [c], asc: c.name) + _ -> order_by(query, [c], [asc: c.name, asc: c.id]) end end diff --git a/lib/components_elixir/inventory/category.ex b/lib/components_elixir/inventory/category.ex index 7f5ecd3..06a09e0 100644 --- a/lib/components_elixir/inventory/category.ex +++ b/lib/components_elixir/inventory/category.ex @@ -18,7 +18,7 @@ defmodule ComponentsElixir.Inventory.Category do has_many :children, Category, foreign_key: :parent_id has_many :components, Component - timestamps() + timestamps(type: :naive_datetime_usec) end @doc false diff --git a/lib/components_elixir/inventory/component.ex b/lib/components_elixir/inventory/component.ex index c6e71c8..bc9280b 100644 --- a/lib/components_elixir/inventory/component.ex +++ b/lib/components_elixir/inventory/component.ex @@ -23,7 +23,7 @@ defmodule ComponentsElixir.Inventory.Component do belongs_to :category, Category belongs_to :storage_location, StorageLocation - timestamps() + timestamps(type: :naive_datetime_usec) end @doc false diff --git a/lib/components_elixir/inventory/storage_location.ex b/lib/components_elixir/inventory/storage_location.ex index de3e74e..3421b4f 100644 --- a/lib/components_elixir/inventory/storage_location.ex +++ b/lib/components_elixir/inventory/storage_location.ex @@ -22,7 +22,7 @@ defmodule ComponentsElixir.Inventory.StorageLocation do has_many :children, StorageLocation, foreign_key: :parent_id has_many :components, Component - timestamps() + timestamps(type: :naive_datetime_usec) end @doc false