codeigniter活动记录中的mysql查询

I am running this query,

$this->db->select('news.news_id, news.title, news.article, news.date_posted, news_assets.news_assets_id, news_assets.url')
        ->from('news_assets')
        ->join('news', 'news_assets.news_news_id = news.news_id', 'left')
        ->order_by('news.date_posted', 'DESC');

        $query = $this->db->get();

        return $query->row_array();

Now this query returns a news article, and it should return any attributed assets from the news assets table, the news assets table has 1:n relationship with news so a news article may have an infinite amount of assets but an asset with only ever have 1 news article.

My question is that when I run this query only one asset for a news article is returned, why would this be?

First of all, as for my thoughts, you should select news and join news_assets because your assets belongs to one news article as I understand.

Also you have $query->row_array(); which returns just one row, but if you have 1+ rows you should use, according to this:

foreach ($query->result_array() as $row) {
   echo $row['title'];
   echo $row['name'];
}

maybe you really have one row in the assets table but if not, i guess your JOIN is wrong, maybe you are doing left instead right or the other way

Try below Query.

    $this->db->select('news.news_id, news.title, news.article, news.date_posted, news_assets.news_assets_id, news_assets.url');
    $this->db->from('news_assets');
    $this->db->join('news', 'news.news_id=news_assets.news_news_id', 'left');
    $this->db->order_by('news.date_posted', 'DESC');