1

I'm searching for a way to have additional fields on relations. The simplest exemple would be; you have stores entries and products entries, and you want to create a many to many relationship with the price as additional information.

How could it be done ?

Thanks in advance,

2

From a database point of view you would have a pivot table between stores and products. And in that pivot table you would have additional columns like the price.

Using native fields

You can‘t do that on a relation field per se. (In this case entry field, assuming that products are entries) But you could wrap a repeatable field around an entry field and a price field, e.g. matrix or table and build the relationship this way. This way you can select products from within a store entry and put a price on each product.

One caveat is that you can’t bulk select products anymore. You’d have to select them one by one.

Alternative solution

You could write a custom module where you create a new field type that solves your problem. This would not result in an actual pivot table but it would work in a similar way. As far as I know a field type's value is bound to be saved in a single database column (may be wrong). However, you could even come up with some kind of bulk editing solution if you want to, although this would require some more work.

2
  • Thanks for you answer ! For the matrix solution, do you think it's as reliable than just creating two models + a pivot table in yee ?
    – Antoine
    Jun 8 '20 at 10:58
  • 1
    It depends on what reliable is for you :) I updated the answer with an alternative solution.
    – Johannes
    Jun 8 '20 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.