Jump to content

JOIN In Processwire selector


Harmster
 Share

Recommended Posts

Hey,

The title may be misleading, I just lack the correct definition.

I have 2 templates, Tags and Images. The tags template has 2 fields, a PageField Image with a link to an image and a TextField Title that functions as a tagname.

Now I am building a search function and I am trying to achieve a 'join' like behavior where I can search on tags (Title) but in the Tags templates but also on Title in the Image templates and join them in a PageArray together (Only the Image templates, just retrieve the Image template with the Tag template's field Image).

How do I achieve this with Processwire Selectors?

In MySQL I think I would do something like this:

SELECT tag as t, image as i
WHERE t.tag=$tag OR i.title=$title
JOIN tag
ON t.image=i.id
//This is far from correct but only used to give an indication of what I am trying to achieve..
Link to comment
Share on other sites

I would think using repeaters on a template would establish relationships between "classes" (I feel strongly like templates behave like classes). Just add your tags on images, and search using the image title/name, and add criterias for tags.

Link to comment
Share on other sites

I read this yday and didn't get it. I have re-read it today and still don't get it fully. Why would you add a pagefield (the reference to the image) on the tag template? Shouldn't it be the other way round? You tag images not "image tags" if that makes sense. So, I would do it this way:

1. Tag templates - 1 field only = title [the tag, e.g. Oz]

2. Images templates - 3 fields (at least) - title; image and multiple pagefield for the tags

In the selector, all I need is to $pages->find("template=images");//Here's your array. It includes page references to the tag pages associated with each image page...

Of course, you can filter further in the selector, e.g. find only images tagged with Oz. 

This sounds too basic....so I feel like I am missing something here and you are actually after something else :-)  ;)

Edited by kongondo
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...