2

这是我正在使用的系列

收费套餐收取

{
    "_id": ObjectId("591abc701c9dfa0a6e7608e6"),
    "fee_package_name": "abc",
    "fee_structure": [{
            "fee_name": "Fee1",
            "fee_amount": 1550
        },
        {
            "fee_name": "Fee2",
            "fee_amount": 1750
        },
        {
            "fee_name": "Fee3",
            "fee_amount": 550
        }
    ],
    "total_fee_amount": 3850.0,
}

学生收费

{
    _id: ObjectId("585a98d7fc6c0468218267f9"),
    applied_fee_packages: [
        {
            fee_package_id: ObjectId("591abc701c9dfa0a6e7608e6"),
            applied_discount: 0
        },
        {
            fee_package_id: ObjectId("591abc701c9dfa0a6e7608e7"),
            applied_discount: 0
        }
    ]
}

Laravel:型号:FeePackage:

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class FeePackage extends Eloquent
{
    protected $collection = 'fee_packages';


    public function studentFee() {
        return $this->belongsTo('App\Models\StudentFee');
    }
}

Laravel:模型:学生费用:

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class StudentFee extends Eloquent
{
    protected $collection = 'student_fees';    

    public function feePackages() {
        return $this->hasMany('App\Models\FeePackage');
    }
}

我试图定义 hasMany 关系,即学生费用 hasMany 费用包,我试图检索一个学生,所有费用包都适用于他。

有了这些文件,我得到了这样的第一笔学生费用:

$feeCollection = StudentFee::with('feePackages')->first();

输出:

{
    _id: "585a98d7fc6c0468218267f9", 
    fee_packages: []
}

我只收到没有给定学生费用 ID 的费用包详细信息的响应。

感谢任何解决此问题的指针。

提前致谢

4

0 回答 0