-
Notifications
You must be signed in to change notification settings - Fork 920
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
[QUESTION] CRUD 1-1 relationship #637
Comments
@ivanmart - there's request for support of one-to-one relationships at #250 Depending on what you need, the way I've implemented such functionality is the following:
At the moment, if you're using the Ajax Table support, the field can't/won't be shown in the list view (i.e. what you get at |
@lloy0076 thank you, doing by this I'm able to add fields to form at least. But is it possible to show certain fields depending on model's attribute value? E.g. if we have Product of type1, we show first set of fields, if not - we show another set. For now I cannot see any way to do that inside the |
BTW, how the mutator should look like? I've tried this:
It works, but it seems a bad idea to save the related model in each mutator. Where would it be better to call this save() method? |
|
#165 - this pull request allows you to hide/show fields depending on a value; it's using a radio button but I can't see why it couldn't be made more generic. Also, if you know the item in
Create would be more difficult but it's probably possible - I think one could make two or more create buttons (or use a radio box or whatever) and depending on which one got clicked or the form parameter one could override the |
@lloy0076 thank you again, your answers are very helpful. Could you explain though two things in your mutator example: |
If the model has not been saved,
Line 71 returns something not defined which makes Laravel itself blow up with a 'using undefined variable' error IIRC. As for your second point, you are correct; however because there isn't 1-1 relationship support the easier and probably more efficient Eloquent |
@lloy0076 I'm having trouble creating a new record. The mutator fires before the parent model is saved, which results in error "Indirect modification of overloaded property". In your mutator, you only prevent this situation, but how do you actually save the value of a related model when creating a new record? |
@ivanmart - I override the
|
I have 3 models: Product, Type1 and Type2. The product can be one of two types, that have different set of attributes. A Product model has one-to-one relations with both Type1 and Type2 models. What I need - is a single edit page for Product model in Backpack, where Type1 or Type2 model fields should appear, depend on product's type. I have two questions:
1.- What could be the best way to integrate it in Backpack?
2.- How do I add a field from related model Type1, for example?
I've tried (in ProductCrudController.php):
doesn't work.
The text was updated successfully, but these errors were encountered: