巴黎 ORM,has_many_through 有限制
Paris ORM, has_many_through with restrictions
在巴黎 ORM 中处理此问题的最佳方法是什么?
我有一组类别和一组供应商资料,其中有一个名为 reatured 的列。目前我的class如下:
<?php
namespace {
/**
* Class Category
*/
class Category extends ConfettiModel
{
public static $_table = 'supplier_directory_category';
/**
* Returns only top level categories - they have no parent
*
* @return bool
*/
public static function topLevel()
{
return self::where('parent', 0);
}
public static function marketing()
{
return self::where('marketing', 'Yes');
}
public function getTable() {
return self::$_table;
}
/**
* Is this a top level category - has no parent
*
* @return bool
*/
public function isTopLevel()
{
return ($this->parentId == 0);
}
/**
* Associated DirectoryProfile's
*
* @return ORMWrapper
*/
public function profiles()
{
return $this->has_many_through('DirectoryProfile', 'CategoryDirectoryProfile', 'category', 'supplier');
}
}
我想添加一个新函数 featuredProfiles()
,它允许我检索与 profiles()
相同的结果,但在这种情况下,我想将其限制为 [=14] 的供应商=].
我不太确定如何做到这一点。
我下了赌注,答案比我预期的要简单:
public function featuredProfiles() {
return $this->profiles()->where('featured', 'Yes');
}
添加 where 作为对联接 table 的查询的一部分。
在巴黎 ORM 中处理此问题的最佳方法是什么?
我有一组类别和一组供应商资料,其中有一个名为 reatured 的列。目前我的class如下:
<?php
namespace {
/**
* Class Category
*/
class Category extends ConfettiModel
{
public static $_table = 'supplier_directory_category';
/**
* Returns only top level categories - they have no parent
*
* @return bool
*/
public static function topLevel()
{
return self::where('parent', 0);
}
public static function marketing()
{
return self::where('marketing', 'Yes');
}
public function getTable() {
return self::$_table;
}
/**
* Is this a top level category - has no parent
*
* @return bool
*/
public function isTopLevel()
{
return ($this->parentId == 0);
}
/**
* Associated DirectoryProfile's
*
* @return ORMWrapper
*/
public function profiles()
{
return $this->has_many_through('DirectoryProfile', 'CategoryDirectoryProfile', 'category', 'supplier');
}
}
我想添加一个新函数 featuredProfiles()
,它允许我检索与 profiles()
相同的结果,但在这种情况下,我想将其限制为 [=14] 的供应商=].
我不太确定如何做到这一点。
我下了赌注,答案比我预期的要简单:
public function featuredProfiles() {
return $this->profiles()->where('featured', 'Yes');
}
添加 where 作为对联接 table 的查询的一部分。