How do I perform joins with lithium models?

后端 未结 2 1832
执笔经年
执笔经年 2020-12-18 06:57

I read through lithium\\data\\model\\query, but I didn\'t see any examples of joins.

2条回答
  •  难免孤独
    2020-12-18 07:27

    If you set up a relationship (using hasOne, hasMany, or belongsTo) you can fetch the related data by supplying a with key in the options of your find call.

    Like this:

    $categories = Categories::find('all', array(
      'with' => 'Products'
    ));
    

    Check out the manual chapter on Relationships for more detail.

提交回复
热议问题