public function isOwnedBy($recordId, $userId = null)
    {
        return (bool)$this->find()
            ->where(['id' => $recordId, 'user_id' => $userId])
            ->first();
    }
public function isOwnedBy($recordId, $userId = null)
    {
        return (bool)$this->find()
            ->where(['id' => $recordId, 'user_id' => $userId])
            ->first();
    }
public function isOwnedBy ( $ recordId , $ userId = null ) { return ( bool ) $ this -> find ( ) -> where ( [ 'id' => $ recordId , 'user_id' => $ userId ] ) -> first ( ) ; }
Checks if a record is owned by an user.

Example:
<code>
$posts->isOwnedBy(2, 4);
</code>
it checks if the posts with ID 2 belongs to the user with ID 4.
@param int $recordId Record ID
@param int $userId User ID
@return bool
Checks if a record is owned by an user .