Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product::items relationship does not work with doesntHave #34

Open
f-liva opened this issue Feb 1, 2023 · 0 comments
Open

Product::items relationship does not work with doesntHave #34

f-liva opened this issue Feb 1, 2023 · 0 comments

Comments

@f-liva
Copy link

f-liva commented Feb 1, 2023

// \App\Models\User
class User extends \Corcel\Model\User {
    use \Corcel\WooCommerce\Traits\HasRelationsThroughMeta;

    public function products()
    {
        return $this
            ->hasManyThroughMeta(\Corcel\WooCommerce\Model\Product::class, 'prod_users', 'post_ID', 'ID')
            ->doesntHave('items');
    }
}

Calling $user->products, the NOT EXISTS sql clause queries the table wppl_woocommerce_order_items instead of wppl_woocommerce_order_itemmeta, generating this error: https://flareapp.io/share/Bm0BLkJ7#F73

This my current workaround to get everything work correctly:

// \App\Models\Corcel\Item
class Item extends \Corcel\WooCommerce\Model\Item
{
   protected $table = 'woocommerce_order_itemmeta';
}

// \App\Models\Corcel\Product
class Product extends \Corcel\WooCommerce\Model\Product
{
    public function items(): HasMany
    {
        return $this->hasManyThroughMeta(Item::class, '_product_id', 'order_item_id', 'order_item_id');
    }
}

// \App\Models\User
class User extends \Corcel\Model\User {
    use \Corcel\WooCommerce\Traits\HasRelationsThroughMeta;

    public function products()
    {
        return $this
            ->hasManyThroughMeta(\App\Models\Corcel\Product::class, 'prod_users', 'post_ID', 'ID')
            ->doesntHave('items');
    }
}

Is this a bug or am I just not understanding something?

I need to build the relationship to get only products, never purchased, related to a specific user via meta prod_users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant