Is it possible to create model for ownList?

40 views
Skip to first unread message
Message has been deleted

Роман Алексеев

unread,
Jan 20, 2018, 10:15:37 AM1/20/18
to redbeanphp
There is $product->with(' ORDER BY position ')->ownPictureList

Is it possible to create model that will automatically "ORDER BY position"
when access $product->ownPictureList?

Lynesth

unread,
Apr 10, 2018, 10:46:00 PM4/10/18
to redbeanphp
You could maybe do thing like this (untested) :

<?php

   
class Product extends RedBean_SimpleModel {

       
public function __get( $prop ) {

           
// If the prop we're looking for is the pictures list
           
if ($prop == "ownPictureList") {

               
/**
                 * Automatically adds ->with(' ORDER BY position ') if you haven't specified with()
                 *
                 * This means it'll actually turn $product->ownPictureList into $product->with(' ORDER BY position ')->ownPictureList
                 * But won't modify something like $product->with(' LIMIT 1, 20 ')->ownProductList
                 * You'd have to modify the following code to check for the ORDER BY clause and add it accordingly if that's what you need.

                 */


               
if (empty($this->bean->withSql)) {
                    $this
->bean->with(' ORDER BY position ');
               
}

           
}

           
// What this function was first meant to return, don't forget it :)
           
return $this->bean->$prop;

       
}

   
}

?>



Regards,

Lyn.
Reply all
Reply to author
Forward
0 new messages