Forum

Thread tagged as: Question, Problem, Runway

Perch Runway Collections and Relationships

Hi

I am currently building a site using Perch and would like to link one collection to another. I have 3 items in each collection, which have some text content and images.

The collection template I am trying to link in the relationship from is below (Projects):

 </div>
    <perch:related id="servicerelation" collection="Services" label="Services">
            <p>
                <perch:content id="service_title" type="text" />    
            </p>
    </perch:related>
    <perch:categories id="proj-cat" label="Project Category" set="projects" required="true" />
</div>

The services collection has a text field for the title that contains spaces between the text. The relation field appears in the projects editor, but it does not find any services by service title to lookup. What could I be missing? Following the author and articles example, I have exactly that?

Any help would be greatly appreciated.

Vinay Jagessar

Vinay Jagessar 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

At a glance that looks like it should be working on. If you turn on debug, what does it output at the end of the edit page?

Debug would suggest its finding the collection fine, but not returning those options in the perch administration view so that I can edit/select them. I aim to render them as a smart lookup text field (similar to how categories render) for an editor to select one or more relationships.

I do receive this error however:

Form not posted or did not validate

When I inspect the HTML it has rendered the text field with I see its created the select element with three options. It has the id as the value for the option, but its not rendering the text in the option tag.

Also, each of my collections (projects and services) have categories each (project category and service category). Could there be a conflict on selection of data to render? As looking through the classes it would seem it renders the select options as categories?

Drew McLellan

Drew McLellan 2638 points
Perch Support

"Form not posted or did not validate" isn't an error, just an indication of state, which can sometimes be useful.

Can you show us the output you're getting?

Hi

The debug SQL on the page is the following:

Debug Message
SELECT u.*, r.* FROM perch2_users u, perch2_user_roles r WHERE u.roleID=r.roleID AND u.userEnabled=1 AND u.userID=1 AND u.userHash='99b701b6fe8749ff275ce27470055c27' LIMIT 1
UPDATE perch2_users SET userHash='2f96a4ad8221678f104f2a7c83943b96' WHERE userID=1
SELECT p.privKey FROM perch2_user_privileges p
SELECT * FROM (SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=1 OR userID=0 ORDER BY userID DESC) AS settings GROUP BY settingID
SELECT collectionID, collectionKey FROM perch2_collections WHERE collectionInAppMenu=1 ORDER BY collectionOrder ASC
SELECT * FROM perch2_collections WHERE collectionID=2 LIMIT 1
SELECT ci.*, r.itemOrder, IF(r.itemLatestRev>r.itemRev,1,0) AS _has_draft FROM perch2_collection_items ci, perch2_collection_revisions r WHERE r.itemID=ci.itemID AND ci.collectionID='2' AND ci.itemRev=r.itemLatestRev AND ci.itemID=10 ORDER BY r.itemOrder ASC
SELECT * FROM perch2_collection_items ci, perch2_collection_revisions r WHERE r.itemID=ci.itemID AND ci.collectionID='2' AND ci.itemRev=r.itemRev AND ci.itemID=10
SELECT * FROM perch2_collection_items ci, perch2_collection_revisions r WHERE r.itemID=ci.itemID AND ci.collectionID='2' AND ci.itemRev=r.itemRev AND r.itemOrder > '1000' ORDER BY r.itemOrder LIMIT 1
SELECT * FROM perch2_collection_items ci, perch2_collection_revisions r WHERE r.itemID=ci.itemID AND ci.collectionID='2' AND ci.itemRev=r.itemRev AND r.itemOrder < '1000' ORDER BY r.itemOrder DESC LIMIT 1
Using template: \templates\content\project.html
Form not posted or did not validate
SELECT itemRev, itemLatestRev FROM perch2_collection_revisions WHERE collectionID=2 AND itemID=10 LIMIT 1
SELECT * FROM perch2_categories c, perch2_category_sets s WHERE c.setID=s.setID AND s.setSlug='projects' ORDER BY catTreePosition ASC
SELECT * FROM perch2_collections WHERE collectionKey='Services' LIMIT 1
SELECT * FROM perch2_collection_items ci, perch2_collection_revisions r WHERE r.itemID=ci.itemID AND ci.collectionID='1' AND ci.itemRev=r.itemRev ORDER BY r.itemOrder ASC
Queries: 15

The page this is from is a collection item called Projects. It has a category and a list of related Services (another collection that itself also has a category).

The HTML rendered is the following:

<select id="perch_10_service[]" name="perch_10_service[]" class="categories" multiple="multiple" style="display: none;"><option value="8"></option><option value="9"></option><option value="11"></option></select>

As you can see it has three options (as I have three services) but its not rendering the content just the option values?

Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you get any errors in your browser console?

No browser errors in the console. I am using the latest version of chrome.

I just tried two new collections and linking one to another using the related tag, and there are no issues. These were standard collections, using the article template (and one adjusted to add the related tag), with no categories on the collection.

My business case, is two collections which also have categories (named the same, so a collection called Services, and a Category called services, similarly for Projects). When I try to use the related tag in a collection after rendering its category (so rendering the project category look up field, and then trying to render the related list of services, from the services collection) it does not render. The markup suggests its rendering the related collection as 'categories'. Is there a naming conflict or issue with the rendering code, as the collection and category are the same? The SQL output suggests its selecting the correct data, its just not rendering the options correctly.

Thanks

Interestingly enough, after updating to 2.8 today, I now have an issue with Categories in the console. When I add a category using the default set and category templates, it clears the category name. And the list view shows an entry but with blank text and I am unable to select and add items to it. Could this be related?

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, as per the other posts, that's just an issue with categories, which has been fixed for 2.8.1.

Thanks, I have read the posts about 2.8.1 and 2.8.2. Any ideas into why collections with categories will not render using the related tag in the edit form next to other categories?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is this a new issue since 2.8?

No it was with 2.7.10. It seems to be related to collections (related) and categories being rendered in the same editor?

Drew McLellan

Drew McLellan 2638 points
Perch Support

And it's still happening with 2.8.2?

Hi

Its still an issue after upgrading. I now have 25 related services (collection) to use against my projects collection items. If I inspect the HTML for the editor page I can see I have the 25 options. The option values are the service collection item ids, but there is no text in the option element. So I cant select anything to add:

<div class="field-wrap"><select id="perch_10_service[]" name="perch_10_service[]" class="categories" multiple="multiple" style="display: none;"><option value="17"></option><option value="18"></option><option value="19"></option><option value="20"></option><option value="21"></option><option value="22"></option><option value="23"></option><option value="24"></option><option value="25"></option><option value="26"></option><option value="27"></option><option value="28"></option><option value="29"></option><option value="30"></option><option value="31"></option><option value="32"></option><option value="33"></option><option value="34"></option><option value="35"></option><option value="36"></option><option value="37"></option><option value="38"></option><option value="39"></option><option value="40"></option><option value="41"></option></select><div class="chosen-container chosen-container-multi chosen-with-drop chosen-container-active" style="width: 290px;" title="" id="perch_10_service___chosen"><ul class="chosen-choices"><li class="search-field"><input type="text" value="Select Some Options" class="default" autocomplete="off" style="width: 149px;"></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div></div></div>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you have a field with title="true" set in the source collection?

Hi

No I did not, but adding that has not made a difference. Its still not rendering the data in the option tag. Looking at the default category and set templates they neither have title=true and yet they render in the same control on the edit page (as it seems categories render the same way as relations).

Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you saved the content since changing the template?

Hi

Thanks! This has fixed it. I am currently re-saving each service collection item to enable this. Many thanks for your help!