Skip to content
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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jayvdb
Copy link
Collaborator

@jayvdb jayvdb commented Jul 31, 2023

This is a demo of

  • adding a fake value into a ForeignKey<T> looks doable, but requires T: Clone in order for the fake T to be stored in the db
  • why adding fake values into a Many<T> looks to be incompatible with how Many is designed

I think it is worthwhile to generate a fake value for ForeignKey<T> , if only because faking with Self::new_raw() is really bad, because it exposes an invalid state that can not otherwise easily be reached.

Self::new()
let obj = Faker.fake::<T>();
let ret = Self::new();
ret.all_values.set(vec![obj]).ok();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Values in all_values are presumed to be already saved, and thus not savable.

The only way I can think to get this working is: a pub fn which loads from the db, and compares it with all parts of this Many to determine which DML is needed to "sync" to the db. This could be of value if there are multiple threads, and the current thread wants to make its version of the Many<T> to be authoritative, despite changes that other threads may have made to the same Many<T>. There are several minefields down that path.

Self::new_raw()
/// A dummy value for T will be created, however it also has to have the Clone
/// trait in order for the mutable value to be obtained so that it can be saved.
impl<T: DataObject + Dummy<Faker>> Dummy<Faker> for ForeignKey<T> {
Copy link
Collaborator Author

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 the T to be saved, IMO we should do:

-impl<T: DataObject + Dummy<Faker>>...
+impl<T: Clone + DataObject + Dummy<Faker>>...

and then document how to save the fake data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant