Support » Plugin: Pods - Custom Content Types and Fields » Relation Field Problem

  • Resolved esinformatica

    (@esinformatica)


    First of all, congratulations for the very valid plugin and thanks Jim True for the great work and support you’re giving for this plugin.
    This is the first time I use pods, and I’m finding it very interesting, but unfortunately, like all new things I’m finding it difficult.

    I am making a very simple project and it consists in creating a simple “Archive” compiled of the visits list that I have in the company by the various customers.
    The structure is very simple and I created 3 New Post Type Content

    1 – Companies List
    Fields:
    Company name
    Address
    Phone

    2 – List of Users
    Fields:
    Username
    Rif_Company -> from Companies List

    3 – Users Visits List
    Fields:
    Date_Visit
    Username_Visit -> from the User List
    Rif_Company_Visit -> from the User List (AutoCompiled)

    The population of “Table 3” should do it through Gravity forms (im using the addon for pods ) where only with automatic selection of the customer’s name should fill in the company field previously assigned in table 2.

    The problem on which I am stuck is the following:

    When I try to relate the field Username_Visit with Username of the table ” List of Users” does not come out and tells me that there is no related field, the same thing is for the company field. 

    Thank you very much to those who will give me a hand for this little project!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jim True

    (@jimtrue)

    If you have the Company being populated/linked from the Users (ie Users are assigned to companies), you don’t need to include it in your Users Visits relationship as the source of it is the ‘user’ post type. You’re repeating yourself trying to include it in that ‘Users Visits’ Post Type.

    If you can’t populate Users Visits Lists from the ‘back-end’ admin, you won’t be able to do it using the Pods Gravity Forms Add-on, either, since you’ll be populating that Post Type with the Gravity Form and connecting the Feed requires that. I can pretty much verify you can’t pull the linked company from the user into the User Visits form because that’s not the source of that connection.

    You’re wanting Gravity Forms to provide a ‘dynamic’ lookup to show the Company for the user and that’s not going to work because Users owns that connection. That is not what the Dynamic Population of the Selection Lists handles; it loads the relationship field from your Post Type only. It can’t do ‘lookup’ against another field for a value to match that it doesn’t have access to.

    It’s fun when ‘simple’ things aren’t really ‘simple’, huh? 😉

    Suggestion: If you’re really just needing to track the User Visit, if they’re not IN the selection list, you want to branch to a form to Add the User and select the Company (subsequently if the company doesn’t exist, you want to branch to a form to add the Company). Then your visit is really just searching for the User and tracking their visit. The company is tied to the User, so for displaying that archive, you’d loop through User Visits, Display each User and display the Company connected to the User linked through that relationship field in Users.

    Does that make more sense?

    Relationships in Pods don’t work against specific fields; they are connections to specific posts in other Post Types. So your connection in List of Users to RIF_Company is a direct relationship to the Companies post type.

    Bidrectional relationships require there to be connected relationship fields:

    ie Users Visits > List of Users and List of Users > User Visits, so if you wanted that bidirectional connection created, you would need a relationship field in List of Users called ‘Visit Log’ that was a relationship to ‘User Visits List’ and was ‘multiple select’. Once you created that field, you could create the bidirectional connection inside User Visits List.

    You don’t have a connection from Users Visits to Companies. The connection is Users to Companies, so you can’t make a relationship there, especially if the actual ‘ownership’ of that relationship is Users (since that’s where you’re tracking the company connection to the users).

    Plugin Author Jim True

    (@jimtrue)

    Also, if you need more help figuring this out, please feel free to join our Slack Chat at https://pods.io/chat/ in the #support channel.

    esinformatica

    (@esinformatica)

    Thanks Jim for the long and exhaustive answer.

    As for the “User Visits” table, I had to create it separately because I will have to create another Post Type that will be the contact person in the company to to assign on the visit!

    As for the use of Gravity Form, it will only be for entering user data. So the customer will fill out independently his personal information and populate the customer data table.

    I’m at the end! My final point now is to be able to create a small summary table with the three post types above in relation

    Ex.
    Username – Visit Date – Company

    I’m finding it difficult to find some examples from which to take a cue to create this summary table.
    Do I have to do a query whit multiple post type to do this? Do you know where I can maybe find some simple examples?

    Thank you very much for your availability

    Plugin Author Jim True

    (@jimtrue)

    Well, your ‘visits’ is the primary post type in this situation (the one that contains all the related information).

    So assuming you have a relationship field from visits to user (I’m calling it related_users) and user is linked to company with related_company, you’d do it pretty much like this:

    [pods name="visits" limit="-1" template="User Visits"]

    With “User Visits” template looking like this:

    `
    [before]
    <table>
    <thead>
    <tr>
    <th>User Name</th>
    <th>Visit Date</th>
    <th>Company</th>
    </tr>
    </thead>
    <tbody>
    [/before]
    <tr>
    <th>{@related_user.display_name}</th>
    <th>{@visit_date}</th>
    <th>{@related_user.related_company.post_title}</th>
    </tr>
    [after]
    </tbody>
    </table>
    [/after]
    `

    Hope that helps. 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.