Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/kaffy/resource_admin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ defmodule Kaffy.ResourceAdmin do
"""
def ordering(resource) do
schema = resource[:schema]
[order_key | _] = ResourceSchema.primary_keys(schema)

Utils.get_assigned_value_or_default(resource, :ordering, desc: order_key)
case ResourceSchema.primary_keys(schema) do
[order_key | _] -> Utils.get_assigned_value_or_default(resource, :ordering, desc: order_key)
[] -> Utils.get_assigned_value_or_default(resource, :ordering, desc: :id)
end
end

@doc """
Expand Down
4 changes: 2 additions & 2 deletions lib/kaffy/resource_schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Kaffy.ResourceSchema do
@moduledoc false

def primary_keys(schema) do
schema.__schema__(:primary_key)
schema.__schema__(:primary_key) || []
end

def excluded_fields(schema) do
Expand Down Expand Up @@ -99,7 +99,7 @@ defmodule Kaffy.ResourceSchema do
end

defp reorder_fields(fields_list, schema) do
[_id, first_field | _fields] = schema.__schema__(:fields)
[first_field | _fields] = schema.__schema__(:fields) -- [:id]

# this is a "nice" feature to re-order the default fields to put the specified fields at the top/bottom of the form
fields_list
Expand Down