Skip to content
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

/table/add form confusing with labels and foreign keys #75

Open
joshrabinowitz opened this issue Sep 7, 2016 · 2 comments
Open

/table/add form confusing with labels and foreign keys #75

joshrabinowitz opened this issue Sep 7, 2016 · 2 comments

Comments

@joshrabinowitz
Copy link
Contributor

joshrabinowitz commented Sep 7, 2016

If I have a two tables and a simple_crud interface like:

create table things ( id int, name varchar, category_id int);
create table categories ( id int, name varchar, );

simple_crud(
 prefix=> '/things',
 db_table=>'things',
 foreign_keys => { strategy_id => { table=>'categories', key_column=>'id', label_column=>'name' }},
 labels => { category_id=>"Category" },
);

Then when viewing the /things/add form , then for the 'category_id' field of the things table will show an input labelled 'category' even though you have to enter a 'category_id'.

In some cases this is correct (when there's only one row in the categories table, then it seems like it'll show a checkbox for that category), but if asking for a category id this is misleading.

@bigpresh
Copy link
Owner

Is this still valid?

Testing the example app, which uses foreign_keys for the employer_id column, it displays the name as employer_id, and gives me the available employer records to select from.

@joshrabinowitz
Copy link
Contributor Author

I see what this is about. I've worked up a branch to illustrate this:

https://github.com/joshrabinowitz/SimpleCRUDTest/compare/foreign-key-labels-gh-75?expand=1

The issue is if you have interfaces like this:

simple_crud(
    record_title=>'thing',
    prefix=> '/things',
    db_table=>'things',
    foreign_keys => { category_id => { table=>'categories', key_column=>'id', label_column=>'name' }},
    labels => { category_id=>"Category" },
);
simple_crud(
    record_title=>'category',
    prefix=> '/categories',
    db_table=>'categories',
);

and you have two tables like this, but with no data:

create table things ( id int PRIMARY KEY AUTO_INCREMENT, name varchar(255), category_id int);
create table categories ( id int PRIMARY KEY AUTO_INCREMENT, name varchar(255) );

Then when you go the /things/add form, there will be two text boxes present, one for the "name' and one for the 'category' (instead of the radiobuttons to chose one of the categories - which here don't exist).

I guess the right thing is to give the user an error message that there are no 'category' records to refer the foreign_key to?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants