mercredi 10 octobre 2018

laravel5.6 how to relation multiple with hasMany, like field 3,9,12,66

I Google for 3days no result.So i get here.It's my first ask.Plaese help me. I've table job_companies like this job_companies table image

The char field position is table job_positions ids.

I tried on model JobCompany relation JobPosition like this

public function position()
{
    return $this->hasMany('App\Entities\Job\JobPosition', 'id', 'position');
}

But it's not work,It's queried SQL

select * from `job_positions` where `job_positions`.`id` in ('3,6,23')

I only get id is 3 row.

How do i query

select * from `job_positions` where `job_positions`.`id` in (3,6,23)

or other idea?

I tried

public function position()
{
    $relation = $this->hasMany('App\Entities\Job\JobPosition', 'id', 'position');
    $relation->getBaseQuery()->orWhereRaw("FIND_IN_SET('job_positions.id', 'job_companies.position')");
    return $relation;
}

But queried

select * from `job_positions` where FIND_IN_SET('job_positions.id', 'job_companies.position') and `job_positions`.`id` in ('3,6,23')

not work.

Table job_positions data little change,but may change,May be 100+ records.

Please forgive me for bad English.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire