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

BelongsTo relation in BREAD form has different form name than the generated name in VoyagerBaseController #3428

Closed
sten opened this issue Jul 30, 2018 · 2 comments · Fixed by #4729

Comments

@sten
Copy link

sten commented Jul 30, 2018

Version information

  • Laravel: v5.6.29
  • Voyager: v1.1.3
  • PHP: 7.1
  • Database: MySQL 5.7.16

Description

When I want to save a new entry of a model with a BelongsTo relationship, I get an SQL error that the foreign key is not included in the INSERT query and that no default value for the foreign key is set:

SQLSTATE[HY000]: General error: 1364 Field 'faq_category_id' doesn't have a default value (SQL: insert into `frequently_asked_questions` (`question`, `answer`, `updated_at`, `created_at`) values (ksdjkdj, <p>skdjlsjdjskl ;kjsdldksdjklsjdkljs</p>, 2018-07-30 18:36:38, 2018-07-30 18:36:38))

This is something that happened after I upgraded from Voyager 1.1.2 to 1.1.3. I did not change anything on my BREAD. I removed the relationship once and then reset it but the same occurs again.

I have been debugging this a bit and found out the following. When a model has a BelongsTo relationship, it appears my blade view generates a different name for the field in the BREAD form than the VoyagerBaseController expects. For example, in the BREAD form and hence also in the request, the field name for the foreign key is faq_category_id (which is also the column name in the database table). However the $row->field variable in the function insertUpdateData has the value frequently_asked_question_belongsto_faq_category_relationship. I am wondering where the difference comes from. Could anyone shed some light on this? Thank you very much!

Could it be related to the Voyager upgrade from 1.1.1 to 1.1.2 to 1.1.3 that my project went through? Do some new assets or views need to be published? Or some command run? I check the installation command but it does much more than what I need (e.g. run database migrations).

@sten
Copy link
Author

sten commented Aug 6, 2018

It appears the BREAD field of the foreign key should also have the visibility Add, Edit and Delete...

This is quite illogical/counterintuitive, since to me the visibility of the foreign key field means that the foreign key field would be shown as a text box (or whatever widget) in the create and edit forms of the BREAD.

Here is a screenshot of my BREAD configuration for a frequently_asked_questions model with relationship to a faq_category model:
screen shot 2018-08-06 at 15 31 46

If all visibilities of faq_category_id are disabled, you get an SQL insert error. This is easily reproducable. I just reinstalled laravel & voyager to test this.

MrCrayon added a commit to MrCrayon/voyager that referenced this issue Feb 1, 2020
In a belongsTo relationship both fields: relationship and foreign key play a role but this is not explained in docs.

Closes thedevdojo#3428
MrCrayon added a commit to MrCrayon/voyager that referenced this issue Feb 1, 2020
In a belongsTo relationship both fields: relationship and foreign key play a role but this is not explained in docs.

Closes thedevdojo#3428
MrCrayon added a commit to MrCrayon/voyager that referenced this issue Mar 24, 2020
In a belongsTo relationship both fields: relationship and foreign key play a role but this is not explained in docs.

Closes thedevdojo#3428
emptynick added a commit that referenced this issue Jan 29, 2021
In a belongsTo relationship both fields: relationship and foreign key play a role but this is not explained in docs.

Closes #3428

Co-authored-by: Christoph Schweppe <[email protected]>
@github-actions
Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant