Diesel 获取单亲和许多孩子 - 火箭

Posted

技术标签:

【中文标题】Diesel 获取单亲和许多孩子 - 火箭【英文标题】:Diesel fetch single parent and many children - Rocket 【发布时间】:2019-11-07 02:42:03 【问题描述】:

我已经能够让所有的父母和所有的孩子一起 任何人都知道如何让所有孩子都成为单亲父母?

pub struct CityAndNeighbourhoods(CustomerCity, Vec<Vec<CustomerNeighbourhood>>);

pub fn get_customer_city_with_neighbourhoods(
    id: i64,
    connection: &PgConnection,
) -> QueryResult<CityAndNeighbourhoods> 
    // Load a single customer_citys given an id
    let city = customer_citys::table
        .find(id)
        .first::<CustomerCity>(&*connection)
        .expect("Error loading city");
    // Load all customer_neighbourhoods belong to the customer_citys above
    // and group by customer_citys
    let neighbourhoods =
        CustomerNeighbourhood::belonging_to(&city).load::<CustomerNeighbourhood>(connection)?;
    // Return all customer_citys with them customer_neighbourhoods
    let data = CityAndNeighbourhoods(city, neighbourhoods.into_iter().zip().collect::<Vec<_>>());
    Ok(data)

【问题讨论】:

【参考方案1】:

创建了一个元组;

pub fn get_customer_city_with_neighbourhoods(
    id: i64,
    connection: &PgConnection,
) -> QueryResult<(CustomerCity, Vec<CustomerNeighbourhood>)> 
    // Load a single customer_citys given an id
    let city = customer_citys::table
        .find(id)
        .first::<CustomerCity>(&*connection)
        .expect("Error loading city");
    // Load all customer_neighbourhoods belong to the customer_citys above
    // and group by customer_citys
    let neighbourhoods =
        CustomerNeighbourhood::belonging_to(&city).load::<CustomerNeighbourhood>(connection)?;
    // Return all customer_citys with them customer_neighbourhoods
    Ok((city, neighbourhoods))

【讨论】:

以上是关于Diesel 获取单亲和许多孩子 - 火箭的主要内容,如果未能解决你的问题,请参考以下文章

我无法安装diesel-cli以与火箭一起使用[重复]

CoreData 获取孩子的父母

获取parentNode(...)孩子的所有孩子

使用谓词在 Core Data 中获取父母的所有孩子

教育适应时代变革,我们的孩子需要了解编程语言!

perl:一个父母,许多孩子 - 父母中有一个管道阅读器?