I'm trying to get values from two related tables using sea-orm. For that I'm using something like:
let paginator = CeccModel::find()
.column_as(
Expr::tbl(Alias::new("cecc_instance"), cecc_instance::Column::CeccId)
.into_simple_expr(),
"cecc_instance_id",
)
.column_as(
Expr::tbl(
Alias::new("cecc_instance"),
cecc_instance::Column::ContractAddress,
)
.into_simple_expr(),
"contract_address",
)
.column_as(
Expr::tbl(Alias::new("cecc_instance"), cecc_instance::Column::Enabled)
.into_simple_expr(),
"enabled",
)
.column_as(
Expr::tbl(
Alias::new("cecc_instance"),
cecc_instance::Column::LastBlockSaved,
)
.into_simple_expr(),
"last_block_saved",
)
.join_as(
sea_orm::JoinType::InnerJoin,
cecc::Relation::CeccInstance.def(),
Alias::new("cecc_instance"),
)
.filter(Condition::any().add(cecc_instance::Column::Enabled.eq(enabled)))
.paginate(db, results_per_page.try_into().unwrap());
let t = paginator
.fetch_page((page - 1).try_into().unwrap())
.await
.map(|p| (p, num_pages)); // here I only obtain values from "cecc" table.
where cecc_instance table has a foreign key corresponding to a registry in cecc table.
When I execute the query, explained lines above, I only obtain the values associated to cecc table. But no the values I also expect from the table cecc_instance.
So I was just wondering if that is the expected behavior or is there something else I am missing or doing wrong.
Please let me know what you think, any help is well received.
Thanks
This is because sea orm is returns data in Model by default in your case CeccModel. Try getting the result as json instead of CeccModel.
Check sea-orm docs for more info: https://www.sea-ql.org/SeaORM/docs/basic-crud/json/