Announcement

Collapse
No announcement yet.

Adding a field to Many-to-many middle table

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding a field to Many-to-many middle table

    Hello. I have a table, let's call it People, and another table Languages. I'd like for each person to have a language and a fluency level (1 to 5). The catch is that I'd like to have it show similar to a 'Link multiple field'. Currently this is possible, but without the extra field 'Fluency level'. Is there a way to add this field to the link multiple field view? For example, for fluency level 4 english, see pic. Thanks!

  • #2
    Hello
    Check, how implemented relations account - contact + accountRole (title), or opportunity and contact with role

    Comment


    • #3
      Perfect, that looks good. I will have a look at the code. Thank you tanya.

      Comment


      • #4
        I am trying to achieve the same thing.
        After looking at the relationships between Account and Contact, I created fields like accountRole but I could not get the field to show up after assigning an entity to the contact.

        Not sure how to completely copy the contacts - accounts scheme to a new entity with subfields like "accountRole".

        What I want to achieve is the following:

        Entity "Contact" has a connection to a "Product" but for every product that is assigned to the "Contact" a price, amount etc. must be set that is attached to this unique relationship (middle table).
        So for the same product different contacts can have different prices, amounts etc.

        I only tried the entity manager and layout manager but no code adjustments.
        Is this even possible without code adjustments?

        Thanks in advance!
        Last edited by phil; 05-04-2018, 09:01 AM.

        Comment


        • #5
          Originally posted by tanya View Post
          I show you the similar usage in EspoCRM but with Accounts and Contacts.
          but here you can set the role (title) of contact on Contact view in Accounts field, but in Account you can see the panel of related contacts with roles.

          Here you can set the role on Property view, but need this field on Contact view in Properties relationship table. That's why I ask you to check, how does implemented in Account and Contact enittyDefs.



          In property layouts create listForContact.json, in clientDefs relate this entity to the panel

          https://github.com/espocrm/espocrm/b...count.json#L50
          Hi,
          open application/Espo/Modules/Crm/Resources/metadata/entityDefs/Contacts.json and Opportunity.json (I think it's easier to understand)

          You can create your relationship with EntityManager (what you did), after you can improve this relationship

          Opportunity > links > contacts has "additionalColumns" option - here you need to define your additional fields for data base
          in Contact fields defined opportunityRole field,
          in Opportunity > contactRole and contacts with columns. Also you need to create a view for your linkMultiple field

          Comment


          • rabii
            rabii commented
            Editing a comment
            Hey Tanya,

            What about creating these views e.g contacts field view in opportunity with role, if we create the custom fields in similar place will these field show in : EnitiyManager -> fields and also in LayoutManager ?

            I hope there is a more simpler step by step reply explaining how to create fields in both related entities and their view

          • jovi
            jovi commented
            Editing a comment
            Thank you Tanya for answer. It really helps (but also require some code researching )

            How I can get additional fields in API request?

            For example, if I do searching by GET /..../MyEntity?select=myFieldIds - I got linked items with names and ids but without additional fields. I already try many combinations like myFieldColumns, myFieldFieldNames and many other - it did't help.
            If I request full record like GET /..../MyEntity/SOME_ID - I got all needs, but doing requests for every searching result is too slow and stupid

        • #6
          That looks really promising!
          Thank you very much for your quick help.

          Comment


          • #7
            you may also declare the middle table as a standard entity, something like ContactsAccounts, then you can link it with both contact and account
            then you can define fields as you want, the only limit is that you cannot set the related records on the fly while you are creating the main entity.
            if this limitation is painful, you can use an extension I made that help for inserting the related entities on the fly like in this video
            CEO & Founder of Eblasoft.
            Professional EspoCRM development & extensions.

            Comment

            Working...
            X