-
Notifications
You must be signed in to change notification settings - Fork 13
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
WIP: Fake relationship members #142
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; | |
use std::borrow::Cow; | ||
|
||
#[cfg(feature = "fake")] | ||
use fake::{Dummy, Faker}; | ||
use fake::{Dummy, Fake, Faker}; | ||
|
||
fn default_oc<T>() -> OnceCell<Vec<T>> { | ||
OnceCell::default() | ||
|
@@ -215,9 +215,15 @@ impl<T: DataObject> Default for Many<T> { | |
} | ||
|
||
#[cfg(feature = "fake")] | ||
/// Fake data support is currently limited to empty Many relationships. | ||
impl<T: DataObject> Dummy<Faker> for Many<T> { | ||
/// Fake data support generates one value, | ||
/// however it is impossible to the many relationship to it. | ||
/// If we put them in `new_values`, we can only store the `.pk()` | ||
/// which makes it impossible to save the value being related to. | ||
impl<T: DataObject + Dummy<Faker>> Dummy<Faker> for Many<T> { | ||
fn dummy_with_rng<R: rand::Rng + ?Sized>(_: &Faker, _rng: &mut R) -> Self { | ||
Self::new() | ||
let obj = Faker.fake::<T>(); | ||
let ret = Self::new(); | ||
ret.all_values.set(vec![obj]).ok(); | ||
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. Values in The only way I can think to get this working is: a |
||
ret | ||
} | ||
} |
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.
If we proceed with this, and
.clone()
is needed to get theT
to be saved, IMO we should do:and then document how to save the fake data.