Jump to content

Searching by repeater subfields in chain


Tim
 Share

Recommended Posts

Hello.

I have a problem with searching by repeater subfields.

For example, there are loans. Each of them has several rates depend on currency. I've implemented it by repeater.

currency | period | percent

------------------------------

USD         12m      5%

EUR         6m      6%

etc.

When I search by subfield:

$pages->find('template=loan, rates.currency=USD, rates.period=6');

I get loans that have at least one rate with currency USD and at least one period = 6

However, I want to retrieve only such loans that have currency = USD AND period = 6

I found this documentation.

If you instead want to find all pages that have at least one building greater than 1000 feet that also happens to be built before 1980 (matching the same exact building, even if the page has multiple buildings) then you can specify that in the selector by preceding the field name with a "@", i.e.

@buildings.feet_high>1000, @buildings.year_built<1980

However 

$pages->find('template=loan, @rates.currency=USD, @rates.period=6');  

doesn't work. :(

Link to comment
Share on other sites

Your approach will not work. If you want to go on with repeaters you have to use nested repeaters. Other options: Page/ PageTabel Field or ProFields Matrix.
More Information about nested repeaters and ProFields Matrix here:
https://processwire.com/blog/posts/more-repeaters-repeater-matrix-and-new-field-rendering/

I would do this job with a simple Page or PageTable Field
Create some fields (currency, period, percent)
Create a template 'rate' and assign the fields above
Create some pages (rates) with template 'rate'

USD         12m      5%

USD         6m      5%
EUR      6m      6%

Create a Page Field 'rates' and use template 'rate' for selectable pages
Assign this Page Field to the 'loan' template.

  • Like 2
Link to comment
Share on other sites

Thank you for a new fresh idea.

I used PageTable field and now it works.

The only confusing thing is that every time I want to add new record I have to enter name of the subpage. Is there any solution to let PW automatically use new page ID as a name?

  • Like 1
Link to comment
Share on other sites

With Standard Processwire Installation you have the option to configure SetupPageName (childNameFormat) under Tab Family in the Parent Template, which allows you to derive (auto assign) the name from title. Until now this is not possible with id. But you could use the following module which extends the SetupPageName function exactly for your needs.
http://modules.processwire.com/modules/process-setup-page-name/
Unfortunately this module doesn't work properly in multilanguage surrounding.

If you want to use the Field in multiple pages it might by better to use a Page field instead of PageTable. If you define Parent and Template in the field settings you can add a new Page from the field too. Pages in PageTable Field must be created/ deleted from Field.

  • Like 1
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...