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

Search in some Entity #297

Open
biohardware opened this issue Apr 20, 2020 · 0 comments
Open

Search in some Entity #297

biohardware opened this issue Apr 20, 2020 · 0 comments

Comments

@biohardware
Copy link

Hi!
Please help me, how to search at the same time in some entities.

my tables:

items:

        'id' => ['type' => 'integer',  'autoincrement' => true, 'primary' => true, 'unsigned' => true, 'unique' => true, 'default' => null],   
        'status' => ['type' => 'integer', 'default' => 0],
        'avaible' => ['type' => 'integer', 'default' => 0],
        'created_by' => ['type' => 'integer', 'unsigned' => true, 'unique' => false, 'default' => null],
        'updated_by' => ['type' => 'integer', 'default' => null, 'unsigned' => true, 'unique' => false],
        'created_at' => ['type' => 'datetime', 'value' => new \DateTime()],
        'updated_at' => ['type' => 'datetime', 'value' => new \DateTime()],

relations:

        'price' => $mapper->hasOne($entity, ItemPrice::class, 'item')->order(['created_at' => 'DESC']),
        'image' => $mapper->hasOne($entity, Images::class, 'item'),
        'hu' => $mapper->hasOne($entity, ItemContent::class, 'item')->where(['lang' => 'hu']),
        'en' => $mapper->hasOne($entity, ItemContent::class, 'item')->where(['lang' => 'en']),
        'item_box' => $mapper->belongsTo($entity, ItemBox::class, 'box'),
        'categories' => $mapper->hasManyThrough($entity, Category::class, ItemCategory::class, 'category_id', 'item_id'),
        'created_user' => $mapper->belongsTo($entity, Admin::class, 'created_by'),
        'updated_user' => $mapper->belongsTo($entity, Admin::class, 'updated_by'),
        'search' => $mapper->hasOne($entity, ItemTitleSearch::class, 'item'),
        'getitem' => $mapper->hasOne($entity, ItemContent::class, 'item'),

item_contents:

        'id' => ['type' => 'integer', 'autoincrement' => true, 'primary' => true, 'unsigned' => true, 'unique' => true],
        'item' => ['type' => 'integer', 'default' => null, 'unsigned' => true, 'unique' => false],
        'lang' => ['type' => 'string', 'required' => true],
        'title' => ['type' => 'string', 'required' => true],
        'description' => ['type' => 'text', 'default' => '']

relations:

       'hu' => $mapper->belongsTo($entity, Items::class, 'item'),
       'en' => $mapper->belongsTo($entity, Items::class, 'item'),

item_categories:(manytomany), hasManyThrough

        'id' => ['type' => 'integer', 'autoincrement' => true, 'primary' => true, 'unsigned' => true, 'unique' => true, 'default' => null],
        'item_id' => ['type' => 'integer', 'default' => 0, 'unsigned' => true, 'unique' => false],
        'category_id' => ['type' => 'integer', 'default' => 0, 'unsigned' => true, 'unique' => false],

relations:

        'item' => $mapper->belongsTo($entity, Items::class, 'item_id'),
        'category' => $mapper->belongsTo($entity, Category::class, 'category_id'),

category:

        'category_id' => ['type' => 'integer', 'default' => 0,'primary' => true, 'unsigned' => true, 'unique' => true],
        'image' => ['type' => 'string'],
        'parent_id' => ['type' => 'integer', 'default' => 0, 'unsigned' => true, 'unique' => false],
        'status' => ['type' => 'integer', 'default' => 0],

relations:

        'hu' => $mapper->hasOne($entity, CategoryDescription::class, 'category_id')->where(['language_id' => 3]),
        'en' => $mapper->hasOne($entity, CategoryDescription::class, 'category_id')->where(['language_id' => 1]),
        'parentcategory' => $mapper->belongsTo($entity, Category::class, 'parent_id'),
        'items' => $mapper->hasManyThrough($entity, Items::class, ItemCategory::class, 'category_id', 'item_id')

ItemTitleSearch:

        'id' => array('type' => 'integer', 'serial' => true),
        'item' => array('type' => 'integer', 'primary' => true,'index' => true, 'required' => true),
        'title' => array('type' => 'text', 'required' => true, 'fulltext' => true),

relations:

        'getitem' => $mapper->hasOne($entity, Items::class, 'id'),

so, a make a search:

$searchText = 'stringintext';
$allItems = $this->entity->mapper(Items\ItemTitleSearch::class);
$allItems = $allItems->where(['title :like' => '%' . $allItems . '%'])

its working good!

But i want search in titles and categories, how can i do it?
Thanks!

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