Skip to content

Instantly share code, notes, and snippets.

@evaldosantos
Created January 3, 2014 19:38
Show Gist options
  • Save evaldosantos/8245026 to your computer and use it in GitHub Desktop.
Save evaldosantos/8245026 to your computer and use it in GitHub Desktop.
class Pessoa extends Eloquent {
protected $table = "pessoa";
public function telefones()
{
return $this->hasMany('Telefone', 'id_pessoa');
}
}
class Telefone extends Eloquent {
protected $table = "telefone";
}
// Example
return Pessoa::find(18629)->telefones;
// Return
string(46) "select top 1 * from [tb_pessoa] where [id] = ?"
string(67) "select * from [tb_telefone] where [tb_telefone].[id_pessoa] is null"
[]
@evaldosantos
Copy link
Author

@valmirphp
Copy link

Tenta

return $this->hasOne('Telefone');

ou

return $this->hasOne('Telefone', 'id_pessoa');

@valmirphp
Copy link

Qual é o tipo de relação da tabelas?

@evaldosantos
Copy link
Author

Uma pessoa -> Um ou mais telefones.
É uma relação simples, já usei ela com mysql...sqlite...mas no sqlsrv simplesmente não ta funcionando.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment