i have this problem; i am using three models Usuario,Idioma,UsarioIdioma;
exists a relationship between they.
Usuario :
- idUsuario
- nombre
- paterno
- materno
Idioma :
- idIdioma
- nombre
- idrActivo
- captura
UsuarioIdioma
- idUsuarioIdioma
- idUsuario
- idIdioma
- nivel
Model : Usuario
class Usuario extends Model {
protected $table = 'btCatUsuario';
protected $primaryKey = 'idUsuario';
protected $morphClass = 'morphUsuario';
public $timestamps = false;
public function idiomasUsuario()
{
return $this->morphMany('App\Models\UsuarioIdioma', null,'idIdioma','idUsuario');
}
}
Model : Idioma
class Idioma extends Model {
protected $table = 'btCatIdioma';
protected $primaryKey = 'idIdioma';
public $timestamps = false;
public static $snakeAttributes = false;
public function idioma()
{
return $this->morphMany('App\Models\UsuarioIdiomas',null,'idIdioma','idUsuario','idIdioma');
}
}
Model : UsuarioIdioma
class UsuarioIdioma extends Model{
protected $table = 'btUsuaIdio';
protected $primaryKey = 'idUsuaIdio';
public $timestamps = false;
public function idiomagable()
{
return $this->morphTo(null,'idIdioma','idUsuario');
}
}
I am using the following form
use App\Models\Usuario;
$idiomas = Usuario::find(1)->idiomas;
dd($idiomas)
and returns me the following
SQLSTATE[22018]: [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Conversion failed when converting the nvarchar value 'morphUsuario' to data type int. (SQL: select * from [btUsuaIdio] where [btUsuaIdio].[idUsuario] = 1 and [btUsuaIdio].[idUsuario] is not null and [btUsuaIdio].[idIdioma] = morphUsuario)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community