-
-
Notifications
You must be signed in to change notification settings - Fork 526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding find_with_linked #1728
Adding find_with_linked #1728
Changes from 5 commits
e1fa993
a0045d7
7a428bb
47d91a3
c7d7a88
7002e7c
886093c
7814855
3a3a335
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ use crate::{ | |
SelectB, SelectTwo, SelectTwoMany, Statement, StreamTrait, TryGetableMany, | ||
}; | ||
use futures::{Stream, TryStreamExt}; | ||
use sea_query::SelectStatement; | ||
use sea_query::{SelectStatement, Value}; | ||
use std::collections::HashMap; | ||
use std::marker::PhantomData; | ||
use std::pin::Pin; | ||
|
||
|
@@ -997,6 +998,27 @@ where | |
L: EntityTrait, | ||
R: EntityTrait, | ||
{ | ||
// #[cfg(feature = "hashable-value")] | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need a nested scope here? |
||
let pkcol = <L::PrimaryKey as Iterable>::iter() | ||
.next() | ||
.expect("should have primary key") | ||
.into_column(); | ||
|
||
let hashmap: HashMap<Value, Vec<R::Model>> = rows.into_iter().fold( | ||
HashMap::<Value, Vec<R::Model>>::new(), | ||
|mut acc: HashMap<Value, Vec<R::Model>>, value: (L::Model, Option<R::Model>)| { | ||
{ | ||
let key = value.0.get(pkcol); | ||
|
||
acc.insert(key, value.1); | ||
} | ||
|
||
acc | ||
}, | ||
); | ||
} | ||
|
||
let mut acc: Vec<(L::Model, Vec<R::Model>)> = Vec::new(); | ||
for (l, r) in rows { | ||
if let Some((last_l, last_r)) = acc.last_mut() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,11 +119,16 @@ where | |
F: EntityTrait, | ||
{ | ||
pub(crate) fn new(query: SelectStatement) -> Self { | ||
Self::new_without_prepare(query) | ||
.prepare_select() | ||
.prepare_order_by() | ||
} | ||
|
||
pub(crate) fn new_without_prepare(query: SelectStatement) -> Self { | ||
Self { | ||
query, | ||
entity: PhantomData, | ||
} | ||
.prepare_select() | ||
.prepare_order_by() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did we invoke |
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think sea_query::Value is not hashable by default and a specified feature is needed
but then the tests would need to also have the feature on in the configuration
my thought for solution is to make sea_query::Value to be hashable by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the 'hashable-value' feature is intended to be added by default.