我有2个模型。 文件模型:
class File extends Model
{
public function user()
{
return $this->belongsTo('App\m_user', 'CODUSER');
}
}
和m_user模型:
class m_user extends Model
{
protected $table = 'm_users';
public function file()
{
return $this->hasMany('App\File', 'id_user');
}
}
下表如下:
Files:
id, id_user, name
m_user:
CODUSER, email
我想与每个用户一起获取文件。我尝试使用此代码,但不返回m_user的值,仅返回file的值:
$file= File::with(['user'])->first();
print_r($file);
结果是:
(...)
[original:protected] => Array
(
[id] => 79
[id_user] => 1
[name] => Sublime Text Build 3211 x64 Setup.exe
)
(...)
[relations:protected] => Array
(
[user] =>
)
这种关系是空白的!我需要获取关系中的用户数据。
更新: 我使用hasOne而不是File模型中的belongsTo来解决此问题。
答案 0 :(得分:0)
看到您在评论中提供的说明,我认为您正在倒退这种关系。要查看与用户关联的文件,您必须:
df['new_col' = np.log(df.groupby('stock_id')['price'].shift()/df['price'])
提示:您的用户模型不是按照最佳做法创建的,应该是MUser。
希望有帮助