Filtering entities by related entity's properties

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yuri
    Member
    • Mar 2014
    • 8495

    #16
    "view": "Fields.Enum",
    "options": [ COPY OPTIONS FROM ACCOUNT ]
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • alasdaircr
      Active Community Member
      • Aug 2014
      • 525

      #17
      So given that this works well, I think I'll look at making it automatic - so the code that creates ormMetadata.php would add every fieldtype that exists as a filter for an entity as a foreign field to any entity which has a relationship with it.

      That shouldn't be too tricky to figure out.

      Comment

      • alasdaircr
        Active Community Member
        • Aug 2014
        • 525

        #18
        Because doing this manually is a bit of a pain.

        Comment

        • alasdaircr
          Active Community Member
          • Aug 2014
          • 525

          #19
          Originally posted by yurikuzn
          "view": "Fields.Enum",
          "options": [ COPY OPTIONS FROM ACCOUNT ]

          I'm looking at Model::getfieldType().

          Can you access one models' field defs from another model.

          eg

          PHP Code:
          getFieldType: function (field) {
                      if (('defs' in this) && ('fields' in this.defs) && (field in this.defs.fields)) {
                          if (this.defs.fields[field].type === 'foreign') {
                              model = GET_MODEL_FROM_NAME(this.defs.fields[field].link);
                              return model.defs.fields[field].type;
                          }
                          else return this.defs.fields[field].type || null;
                      }
                      return null;
                  }, 
          

          Comment

          • alasdaircr
            Active Community Member
            • Aug 2014
            • 525

            #20
            More thinking required, but am getting somewhere thanks

            Comment

            • alasdaircr
              Active Community Member
              • Aug 2014
              • 525

              #21
              So I was looking at this again last night.

              During a rebuild, after the Unifier stage, I will scan the metadata and create the foreign fields. I will also modify the clientLayouts so that the filters are available.

              But the problem is in the client code, where I need to get the properties of the foreign fields - ie the default option, min/max, enumerations, etc. Do you have a suggestion on how to do that?

              Comment

              • yuri
                Member
                • Mar 2014
                • 8495

                #22
                You don't need the most of params from foreign field. Only "options".
                If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

                Comment

                • alasdaircr
                  Active Community Member
                  • Aug 2014
                  • 525

                  #23
                  Yes, but is there a cleaner way to do this, other than scraping through the metadata structure?

                  Comment

                  • yuri
                    Member
                    • Mar 2014
                    • 8495

                    #24
                    Don't think so.
                    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

                    Comment

                    • alasdaircr
                      Active Community Member
                      • Aug 2014
                      • 525

                      #25
                      Hi Im revisiting this, as I really need the functionality.

                      I can get the options for the foreign field from getMetadata() in side views/search/filter.js however how & where do I apply these and to what object?

                      Comment

                      • hi-ko
                        Member
                        • May 2015
                        • 90

                        #26
                        Has the field type foreign for any field except name and id been removed? I can't get this working and can't find any implementation in the code.

                        Comment

                        Working...