Custom search issues

<%- if @topic_view.topic.tags.present? %>
<%= t 'js.tagging.tags' %>: <%- @topic_view.topic.tags.each do |t| %> <%= t %> <%- end %>
<% end %>

Hi all,
I’m new to SS so sorry if I’m putting stupid questions but couldn’t find much about what I’m trying to achieve.
So given that we have a list of properties
And each property has photos that are sortable and have an image.
then when I seach I need to return also images for each property like

$this->list = new SQLSelect();
$this->list->setFrom('PropertyListing');
$this->list->setWhere(['ListingType' => $this->ListingType]);
$this->apply_filters();

$pages = new PaginatedList(new SQLQueryList($this->list), Controller::curr()->getRequest());
$pages->setPageLength($this->ListingsPerPage);

foreach ($pages as $k_p => $p) {
    $photos = PropertyPhoto::get()->filter(['PropertyListingID' => $p->ID])->sort('Sort ASC')->limit(3)->toArray();
    foreach ($photos as $k_photo => $photo) {
        $photos[$k_photo]->Image = $photo->Image;
    }
    $p->PropertyPhotos = $photos;
    dd($pages);
}

If the photos are related to the Property Listing, and the Images are related to the Photos object then you shouldn’t need to worry about SQL queries. The ORM should make them all available via the listing object. (I’ve made some assumptions about the relation names)

So in PHP it would be something like:

$photos = $propertyListing->Photos();
foreach ($photos as $photo) {
  $photoURL = $photo->Image()->url;
}

or in the template:

<% loop $PropertyListings %>
  $Title //This is the data from the listing
  <% loop $Photos %>
    $Image  //  or something like <img src="$Image.ScaleWidth(500).URL" alt="$Up.Title"/>
  <% end_loop %>
<% end_loop %>

If I’ve missed the point, can you add a bit more description about how everything is connected, etc.

i was checking this to see if there are any other resonses and at the bottom of this list … i’ve got (while not signed in)

Hello! Looks like you’re enjoying the discussion, but you haven’t signed up for an account yet.

makes me laugh … if you are getting to a bottom of a list like this is …because you didn’t find an answer.
It exactly like Silverstripe … a mistake / wrong choice

Sad to say but …that’s the truth


class PropertyListing extends DataObject
{
    private static $has_many = [
        'PropertyPhotos' => PropertyPhoto::class,
    ];
}

class PropertyPhoto extends DataObject
{
    private static $has_one = [
        'PropertyListing' => 'PropertyListing',
        'Image' => Image::class
    ];

    private static $owns = [
        'PropertyListing',
        'Image'
    ];
}

class PropertyPageController extends PageController
{
    public function PropertyListings()
    {
        $this->list = new SQLSelect();
        $this->list->setFrom('PropertyListing');
        $p = Postcode::get()->filter(['Postcode' => $postcode])->first();
        if ($p) {
            $this->list->selectField('(
        3959 * acos (
          cos ( radians(' . $p->Latitude . ') )
          * cos( radians( Latitude ) )
          * cos( radians( Longitude ) - radians(' . $p->Longitude . ') )
          + sin ( radians(' . $p->Latitude . ') )
          * sin( radians( Latitude ) )
        )
      ) AS distance');
            $this->list->setHaving('distance < ' . $distance);
            $this->list->setOrderBy('distance', 'ASC');
        }
        $pages = new PaginatedList(new SQLQueryList($this->list), Controller::curr()->getRequest());
        $pages->setPageLength($this->ListingsPerPage);

        return $pages;
    }
}

SQLSelect
is this
github.com /silvershop/silverstripe-sqlquerylist/blob/master/src/SQLQueryList.php

in template

<% loop $PropertyListings %>
	<% loop $PropertyPhotos.Limit(3).Sort('Sort', 'ASC') %>
		<div class="box box-$Pos bg-cover” style="background-image: url('$Image.ScaleMaxWidth(200).Link')"></div>
	<% end_loop %>
<% end_loop %>

the result:
the only queries for PropertyPhotos happen on the first 2 listings with the id 22 and 21, …
problems
see limit 1 (where is this coming from )
why only on the first 2 out of the 10 pagination

590μs0B2Navigation.ss > SSViewerProxy->process:764 > Page.ss > SSViewerProxy->process:300development
SELECT "ClickToShowFields"
 FROM "PropertyPhoto"
 WHERE ("PropertyPhoto"."PropertyListingID" = 22)
 ORDER BY "PropertyPhoto"."Sort" ASC
 LIMIT 1640μs0B1PropertyGrid.ss > SSViewerProxy->process:764 > Navigation.ss > SSViewerProxy->process:764development
SELECT "ClickToShowFields"
 FROM "File_Live"
 WHERE ("File_Live"."ID" = 477)
 AND ("File_Live"."ClassName" IN ('SilverStripe\\Assets\\Image'))
 ORDER BY "File_Live"."Name" ASC
 LIMIT 1560μs0B1PropertyGrid.ss > SSViewerProxy->process:764 > Navigation.ss > SSViewerProxy->process:764development
SELECT "ClickToShowFields"
 FROM "PropertyPhoto"
 WHERE ("PropertyPhoto"."PropertyListingID" = 21)
 ORDER BY "PropertyPhoto"."Sort" ASC
 LIMIT 1389μs0B1PropertyGrid.ss > SSViewerProxy->process:764 > Navigation.ss > SSViewerProxy->process:764development
SELECT "ClickToShowFields"
 FROM "File_Live"
 WHERE ("File_Live"."ID" = 472)
 AND ("File_Live"."ClassName" IN ('SilverStripe\\Assets\\Image'))
 ORDER BY "File_Live"."Name" ASC
 LIMIT 1

i suspect is something to do with SQLQueryList
but there is no documentation on how to shovel a simple SQLSelect into a PaginatedList