-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support alternate primary keys / remove assumption of :id
key on struct
#88
Comments
Hi @JohnnyCurran thanks for bringing this to my attention. Can you share any more info about your schema? Are you using a different naming scheme for your primary keys? |
@tfwright The data comes from an external API and we use it basically as a cache so we aren't doing http calls to fetch it. This is the only schema we have named this way. Table was created with primary_key: false: create table(:business_redacted, primary_key: false) and then the schema is decorated with: @primary_key {:unitid, :integer, autogenerate: false} For the time being, I've added: field :id, :string, virtual: true to our schema so that live_admin works EDIT: Live_admin works for viewing, but not for editing with the addition of the virtual field. I'll keep digging to see if this is related to the Edit 2: Looks like we have an |
OK yeah I think LiveAdmin just needs to be made aware of primary keys with alternate names. Probably this should be doable without requiring additional config by reflecting on the schema struct, but I'll take a closer look at let you know. |
@JohnnyCurran if you want to try out the changes in #89 they should allow you to use your custom primary key without any additional config. Let me know if you run into any issues! |
@tfwright I can confirm this allowed me to use it without defining a virtual To note: I did need to derive |
@JohnnyCurran thanks for reminding me of the issue with |
Describe the bug
If a schema does not have an
:id
key, it cannot be rendered with LiveAdmin due to the assumption on line 109 atlive_admin/lib/live_admin/components/resource/index.ex
Line 109 in c512842
To Reproduce
Steps to reproduce the behavior:
0. Create a schema without an
:id
keyExpected behavior
Resource should show correctly
Screenshots
If applicable, add screenshots to help explain your problem.
Environment:
Additional context
Conversation starts here https://elixirforum.com/t/liveadmin-phoenix-admin-ui-built-on-liveview/46421/33?u=johnnycurran
The text was updated successfully, but these errors were encountered: