문제

I want to search for records which match on two fields with two supplied objects, for example

 $cnt = $this->usedCouponRepository->findByUser($validvip)->toArray() ;
 $cnt2 = $this->usedCouponRepository->findByCoupon($validcoupon)->toArray() ;

get interesection, (find how many times validvip pairs up with validcoupon in the usedcoupon table) a call like this would be it -

$cnt3 = $this->usedCouponRepository->findByUserAndCoupon($validcoupon,$validuser);

is there a magic function to do this or some other efficient way? I'd hate to just loop over the first looking for a match in code. Thanks

도움이 되었습니까?

해결책

Nope, there is no "extbase magic" doing this job for you. You have to implement it yourself. But lucky you, its not that hard. Just add a method to your repository like this one:

public function findByUserAndCoupon($validcoupon, $validuser) {
    $query = $this->createQuery();
    $query->matching(
        $query->logicalAnd(
            $query->equals('user', $validuser),
            $query->equals('coupon', validcoupon)
        )
    );
    $result = $query->execute();
    return $result;
}

Now you can call this like you tried before. The strings 'user' and 'coupon' in the logicalAnd Statement have to be the fieldnames of the database.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top