use super::{
builders::{
InjectRelationValues, build_belongs_to_many_query, build_morph_to_many_query,
model_key_field,
},
morph_to_impls::{
InjectMorphRelationValues, MorphToMutTargetSpec, MorphToTargetSpec, MorphTypeFieldInfo,
},
*,
};
impl<'a, Child, Parent, ForeignKey, ForeignMeta, OwnerKey, OwnerMeta, OwnerField> BelongsTo<Parent>
for BuiltBelongsTo<'a, Child, Parent, ForeignKey, ForeignMeta, OwnerKey, OwnerMeta, OwnerField>
where
Parent: Qrafting + FromRow,
ForeignMeta: crate::TypeMeta,
OwnerMeta: Comparable + crate::Nullability,
OwnerField: ReadableField<Parent, OwnerKey, OwnerMeta>,
ForeignKey: crate::Compatible<OwnerMeta>,
crate::BinaryType<crate::NullOf<OwnerMeta>, crate::NullOf<OwnerMeta>>: crate::PredicateType,
{
fn into_query(self) -> QueryOf<Parent> {
<Parent as Qrafting>::__qraft_query().filter(
self.owner_key
.column()
.eq((self.foreign_key.getter())(self.child)),
)
}
}
impl<'a, Child, Parent, ForeignKey, ForeignMeta> BelongsTo<Parent>
for RequiredBelongsToBuilder<'a, Child, ForeignKey, ForeignMeta>
where
Parent: Qrafting + FromRow + ModelKey,
<Parent as ModelKey>::Key: crate::DefaultMeta,
ForeignMeta: crate::TypeMeta,
ForeignKey: crate::Compatible<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta: Comparable + crate::Nullability,
crate::BinaryType<
crate::NullOf<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
crate::NullOf<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
>: crate::PredicateType,
{
fn into_query(self) -> QueryOf<Parent> {
self.owner_model_key::<Parent>().into_query()
}
}
impl<'a, Child, Parent, ForeignKey, ForeignMeta, OwnerKey, OwnerMeta, OwnerField>
NullableBelongsTo<Parent>
for BuiltNullableBelongsTo<
'a,
Child,
Parent,
ForeignKey,
ForeignMeta,
OwnerKey,
OwnerMeta,
OwnerField,
>
where
Parent: Qrafting + FromRow,
ForeignMeta: crate::TypeMeta,
OwnerMeta: Comparable + crate::Nullability,
OwnerField: ReadableField<Parent, OwnerKey, OwnerMeta>,
ForeignKey: crate::Compatible<OwnerMeta>,
crate::BinaryType<crate::NullOf<OwnerMeta>, crate::NullOf<OwnerMeta>>: crate::PredicateType,
{
fn into_optional_query(self) -> OptionalQuery<Parent> {
OptionalQuery::new(
((self.foreign_key.getter())(self.child))
.as_ref()
.map(|value| {
<Parent as Qrafting>::__qraft_query().filter(self.owner_key.column().eq(value))
}),
)
}
}
impl<'a, Child, Parent, ForeignKey, ForeignMeta> NullableBelongsTo<Parent>
for NullableBelongsToBuilderImpl<'a, Child, ForeignKey, ForeignMeta>
where
Parent: Qrafting + FromRow + ModelKey,
<Parent as ModelKey>::Key: crate::DefaultMeta,
ForeignMeta: crate::TypeMeta,
ForeignKey: crate::Compatible<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta: Comparable + crate::Nullability,
crate::BinaryType<
crate::NullOf<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
crate::NullOf<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
>: crate::PredicateType,
{
fn into_optional_query(self) -> OptionalQuery<Parent> {
self.owner_model_key::<Parent>().into_optional_query()
}
}
impl<'a, Child, ForeignKey, ForeignMeta, MorphField, Parent, OwnerField>
MorphToTargetBuilder<
'a,
Child,
PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>,
MorphField,
Parent,
OwnerField,
>
where
Child: Qrafting + FromRow,
Parent: Qrafting + FromRow + 'static,
ForeignMeta: crate::TypeMeta,
OwnerField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<OwnerField as ReadableFieldInfo<Parent>>::Value,
<OwnerField as ReadableFieldInfo<Parent>>::Meta,
> + Copy
+ 'static,
<OwnerField as ReadableFieldInfo<Parent>>::Meta: Comparable + crate::Nullability + 'static,
ForeignKey: crate::Compatible<<OwnerField as ReadableFieldInfo<Parent>>::Meta>
+ RelationForeignKeyRef<<OwnerField as ReadableFieldInfo<Parent>>::Value>,
MorphField: MorphTypeFieldInfo<Child>,
crate::BinaryType<
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
>: crate::PredicateType,
{
fn into_built(
self,
) -> BuiltMorphTo<
'a,
Child,
PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>,
MorphField,
> {
let mut targets = self.targets;
let owner_key = self.owner_key;
let morph_name = self.morph_name;
targets.push(MorphToTargetSpec {
type_id: TypeId::of::<Parent>(),
morph_name,
query: Box::new(move |foreign_key, child| {
Some(
<Parent as Qrafting>::__qraft_query()
.filter(owner_key.column().eq((foreign_key.getter())(child)))
.untyped(),
)
}),
});
BuiltMorphTo {
child: self.child,
foreign_key: self.foreign_key,
morph_type: self.morph_type,
targets,
}
}
pub fn morph<Next>(
self,
) -> MorphToTargetBuilder<
'a,
Child,
PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>,
MorphField,
Next,
ModelField<
Next,
<Next as ModelKey>::Key,
<<Next as ModelKey>::Key as crate::DefaultMeta>::Meta,
>,
>
where
Next: Qrafting + FromRow + ModelKey + MorphName + 'static,
<Next as ModelKey>::Key: crate::DefaultMeta,
{
let built = self.into_built();
MorphToTargetBuilder {
child: built.child,
foreign_key: built.foreign_key,
morph_type: built.morph_type,
targets: built.targets,
morph_name: <Next as MorphName>::morph_name(),
owner_key: model_key_field::<Next>(),
_marker: PhantomData,
}
}
}
impl<'a, Child, ForeignKey, ForeignMeta, MorphField, Parent, OwnerField>
MorphToTargetBuilder<
'a,
Child,
PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>,
MorphField,
Parent,
OwnerField,
>
where
Child: Qrafting + FromRow,
Parent: Qrafting + FromRow + 'static,
ForeignMeta: crate::TypeMeta,
OwnerField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<OwnerField as ReadableFieldInfo<Parent>>::Value,
<OwnerField as ReadableFieldInfo<Parent>>::Meta,
> + Copy
+ 'static,
<OwnerField as ReadableFieldInfo<Parent>>::Meta: Comparable + crate::Nullability + 'static,
ForeignKey: crate::Compatible<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
Option<ForeignKey>: RelationForeignKeyRef<<OwnerField as ReadableFieldInfo<Parent>>::Value>,
MorphField: MorphTypeFieldInfo<Child>,
crate::BinaryType<
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
>: crate::PredicateType,
{
fn into_built(
self,
) -> BuiltMorphTo<
'a,
Child,
PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>,
MorphField,
> {
let mut targets = self.targets;
let owner_key = self.owner_key;
let morph_name = self.morph_name;
targets.push(MorphToTargetSpec {
type_id: TypeId::of::<Parent>(),
morph_name,
query: Box::new(move |foreign_key, child| {
(foreign_key.getter())(child).as_ref().map(|value| {
<Parent as Qrafting>::__qraft_query()
.filter(owner_key.column().eq(value))
.untyped()
})
}),
});
BuiltMorphTo {
child: self.child,
foreign_key: self.foreign_key,
morph_type: self.morph_type,
targets,
}
}
pub fn morph<Next>(
self,
) -> MorphToTargetBuilder<
'a,
Child,
PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>,
MorphField,
Next,
ModelField<
Next,
<Next as ModelKey>::Key,
<<Next as ModelKey>::Key as crate::DefaultMeta>::Meta,
>,
>
where
Next: Qrafting + FromRow + ModelKey + MorphName + 'static,
<Next as ModelKey>::Key: crate::DefaultMeta,
{
let built = self.into_built();
MorphToTargetBuilder {
child: built.child,
foreign_key: built.foreign_key,
morph_type: built.morph_type,
targets: built.targets,
morph_name: <Next as MorphName>::morph_name(),
owner_key: model_key_field::<Next>(),
_marker: PhantomData,
}
}
}
impl<'a, Child: Draftable, ForeignKey, ForeignMeta, MorphField, Parent, OwnerField>
MorphToMutTargetBuilder<
'a,
Child,
PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>,
MorphField,
Parent,
OwnerField,
>
where
Child: Qrafting + FromRow + Draftable,
Parent: Qrafting + FromRow + 'static,
ForeignMeta: crate::TypeMeta,
OwnerField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<OwnerField as ReadableFieldInfo<Parent>>::Value,
<OwnerField as ReadableFieldInfo<Parent>>::Meta,
> + Copy
+ 'static,
<OwnerField as ReadableFieldInfo<Parent>>::Meta: Comparable + crate::Nullability + 'static,
ForeignKey: crate::Compatible<<OwnerField as ReadableFieldInfo<Parent>>::Meta>
+ RelationForeignKeyRef<<OwnerField as ReadableFieldInfo<Parent>>::Value>,
MorphField: MorphTypeFieldInfo<Child>,
crate::BinaryType<
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
>: crate::PredicateType,
{
fn into_built(
self,
) -> BuiltMorphToMut<
'a,
Child,
PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>,
MorphField,
> {
let mut targets = self.targets;
let owner_key = self.owner_key;
let morph_name = self.morph_name;
targets.push(MorphToMutTargetSpec {
type_id: TypeId::of::<Parent>(),
morph_name,
query: Box::new(move |foreign_key, child| {
Some(
<Parent as Qrafting>::__qraft_query()
.filter(owner_key.column().eq((foreign_key.getter())(child)))
.untyped(),
)
}),
assign: Box::new(move |foreign_key, child, parent| {
let parent = parent
.downcast_ref::<Parent>()
.expect("morph_to target type mismatch");
(foreign_key.setter())(
child,
ForeignKey::from_relation_key_ref((owner_key.getter())(parent)),
);
vec![foreign_key.dirty_field()]
}),
});
BuiltMorphToMut {
child: self.child,
foreign_key: self.foreign_key,
morph_type: self.morph_type,
targets,
}
}
pub fn morph<Next>(
self,
) -> MorphToMutTargetBuilder<
'a,
Child,
PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>,
MorphField,
Next,
ModelField<
Next,
<Next as ModelKey>::Key,
<<Next as ModelKey>::Key as crate::DefaultMeta>::Meta,
>,
>
where
Next: Qrafting + FromRow + ModelKey + MorphName + 'static,
<Next as ModelKey>::Key: crate::DefaultMeta,
{
let built = self.into_built();
MorphToMutTargetBuilder {
child: built.child,
foreign_key: built.foreign_key,
morph_type: built.morph_type,
targets: built.targets,
morph_name: <Next as MorphName>::morph_name(),
owner_key: model_key_field::<Next>(),
_marker: PhantomData,
}
}
}
impl<'a, Child: Draftable, ForeignKey, ForeignMeta, MorphField, Parent, OwnerField>
MorphToMutTargetBuilder<
'a,
Child,
PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>,
MorphField,
Parent,
OwnerField,
>
where
Child: Qrafting + FromRow + Draftable,
Parent: Qrafting + FromRow + 'static,
ForeignMeta: crate::TypeMeta,
OwnerField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<OwnerField as ReadableFieldInfo<Parent>>::Value,
<OwnerField as ReadableFieldInfo<Parent>>::Meta,
> + Copy
+ 'static,
<OwnerField as ReadableFieldInfo<Parent>>::Meta: Comparable + crate::Nullability + 'static,
ForeignKey: crate::Compatible<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
Option<ForeignKey>: RelationForeignKeyRef<<OwnerField as ReadableFieldInfo<Parent>>::Value>,
MorphField: MorphTypeFieldInfo<Child>,
crate::BinaryType<
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
>: crate::PredicateType,
{
fn into_built(
self,
) -> BuiltMorphToMut<
'a,
Child,
PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>,
MorphField,
> {
let mut targets = self.targets;
let owner_key = self.owner_key;
let morph_name = self.morph_name;
targets.push(MorphToMutTargetSpec {
type_id: TypeId::of::<Parent>(),
morph_name,
query: Box::new(move |foreign_key, child| {
(foreign_key.getter())(child).as_ref().map(|value| {
<Parent as Qrafting>::__qraft_query()
.filter(owner_key.column().eq(value))
.untyped()
})
}),
assign: Box::new(move |foreign_key, child, parent| {
let parent = parent
.downcast_ref::<Parent>()
.expect("morph_to target type mismatch");
(foreign_key.setter())(
child,
Option::<ForeignKey>::from_relation_key_ref((owner_key.getter())(parent)),
);
vec![foreign_key.dirty_field()]
}),
});
BuiltMorphToMut {
child: self.child,
foreign_key: self.foreign_key,
morph_type: self.morph_type,
targets,
}
}
pub fn morph<Next>(
self,
) -> MorphToMutTargetBuilder<
'a,
Child,
PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>,
MorphField,
Next,
ModelField<
Next,
<Next as ModelKey>::Key,
<<Next as ModelKey>::Key as crate::DefaultMeta>::Meta,
>,
>
where
Next: Qrafting + FromRow + ModelKey + MorphName + 'static,
<Next as ModelKey>::Key: crate::DefaultMeta,
{
let built = self.into_built();
MorphToMutTargetBuilder {
child: built.child,
foreign_key: built.foreign_key,
morph_type: built.morph_type,
targets: built.targets,
morph_name: <Next as MorphName>::morph_name(),
owner_key: model_key_field::<Next>(),
_marker: PhantomData,
}
}
}
impl<'a, Child, ForeignField, MorphField> MorphTo
for BuiltMorphTo<'a, Child, ForeignField, MorphField>
where
Child: Qrafting + FromRow,
ForeignField: Copy,
MorphField: MorphTypeFieldInfo<Child>,
{
fn as_morph<Parent>(self) -> OptionalQuery<Parent>
where
Parent: Qrafting + FromRow + ModelKey + 'static,
{
let type_id = TypeId::of::<Parent>();
let Some(target) = self.targets.iter().find(|target| target.type_id == type_id) else {
return OptionalQuery::new(None);
};
if !self.morph_type.matches(self.child, target.morph_name) {
return OptionalQuery::new(None);
}
OptionalQuery::new((target.query)(self.foreign_key, self.child).map(Query::typed::<Parent>))
}
}
impl<'a, Child: Draftable, ForeignField, MorphField> MorphTo
for BuiltMorphToMut<'a, Child, ForeignField, MorphField>
where
Child: Qrafting + FromRow + Draftable,
ForeignField: Copy,
MorphField: MorphTypeFieldInfo<Child>,
{
fn as_morph<Parent>(self) -> OptionalQuery<Parent>
where
Parent: Qrafting + FromRow + ModelKey + 'static,
{
let type_id = TypeId::of::<Parent>();
let child = &*self.child;
let Some(target) = self.targets.iter().find(|target| target.type_id == type_id) else {
return OptionalQuery::new(None);
};
if !self.morph_type.matches(child, target.morph_name) {
return OptionalQuery::new(None);
}
OptionalQuery::new((target.query)(self.foreign_key, child).map(Query::typed::<Parent>))
}
}
impl<'a, Child, ForeignKey, ForeignMeta, MorphField, Parent, OwnerField> MorphTo
for MorphToTargetBuilder<
'a,
Child,
PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>,
MorphField,
Parent,
OwnerField,
>
where
Child: Qrafting + FromRow,
Parent: Qrafting + FromRow + 'static,
ForeignMeta: crate::TypeMeta,
OwnerField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<OwnerField as ReadableFieldInfo<Parent>>::Value,
<OwnerField as ReadableFieldInfo<Parent>>::Meta,
> + Copy
+ 'static,
<OwnerField as ReadableFieldInfo<Parent>>::Meta: Comparable + crate::Nullability + 'static,
ForeignKey: crate::Compatible<<OwnerField as ReadableFieldInfo<Parent>>::Meta>
+ RelationForeignKeyRef<<OwnerField as ReadableFieldInfo<Parent>>::Value>,
MorphField: MorphTypeFieldInfo<Child>,
crate::BinaryType<
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
>: crate::PredicateType,
{
fn as_morph<Target>(self) -> OptionalQuery<Target>
where
Target: Qrafting + FromRow + ModelKey + 'static,
{
self.into_built().as_morph::<Target>()
}
}
impl<'a, Child, ForeignKey, ForeignMeta, MorphField, Parent, OwnerField> MorphTo
for MorphToTargetBuilder<
'a,
Child,
PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>,
MorphField,
Parent,
OwnerField,
>
where
Child: Qrafting + FromRow,
Parent: Qrafting + FromRow + 'static,
ForeignMeta: crate::TypeMeta,
OwnerField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<OwnerField as ReadableFieldInfo<Parent>>::Value,
<OwnerField as ReadableFieldInfo<Parent>>::Meta,
> + Copy
+ 'static,
<OwnerField as ReadableFieldInfo<Parent>>::Meta: Comparable + crate::Nullability + 'static,
ForeignKey: crate::Compatible<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
Option<ForeignKey>: RelationForeignKeyRef<<OwnerField as ReadableFieldInfo<Parent>>::Value>,
MorphField: MorphTypeFieldInfo<Child>,
crate::BinaryType<
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
>: crate::PredicateType,
{
fn as_morph<Target>(self) -> OptionalQuery<Target>
where
Target: Qrafting + FromRow + ModelKey + 'static,
{
self.into_built().as_morph::<Target>()
}
}
impl<'a, Child: Draftable, ForeignKey, ForeignMeta, MorphField, Parent, OwnerField> MorphTo
for MorphToMutTargetBuilder<
'a,
Child,
PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>,
MorphField,
Parent,
OwnerField,
>
where
Child: Qrafting + FromRow + Draftable,
Parent: Qrafting + FromRow + 'static,
ForeignMeta: crate::TypeMeta,
OwnerField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<OwnerField as ReadableFieldInfo<Parent>>::Value,
<OwnerField as ReadableFieldInfo<Parent>>::Meta,
> + Copy
+ 'static,
<OwnerField as ReadableFieldInfo<Parent>>::Meta: Comparable + crate::Nullability + 'static,
ForeignKey: crate::Compatible<<OwnerField as ReadableFieldInfo<Parent>>::Meta>
+ RelationForeignKeyRef<<OwnerField as ReadableFieldInfo<Parent>>::Value>,
MorphField: MorphTypeFieldInfo<Child>,
crate::BinaryType<
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
>: crate::PredicateType,
{
fn as_morph<Target>(self) -> OptionalQuery<Target>
where
Target: Qrafting + FromRow + ModelKey + 'static,
{
self.into_built().as_morph::<Target>()
}
}
impl<'a, Child: Draftable, ForeignKey, ForeignMeta, MorphField, Parent, OwnerField> MorphTo
for MorphToMutTargetBuilder<
'a,
Child,
PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>,
MorphField,
Parent,
OwnerField,
>
where
Child: Qrafting + FromRow + Draftable,
Parent: Qrafting + FromRow + 'static,
ForeignMeta: crate::TypeMeta,
OwnerField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<OwnerField as ReadableFieldInfo<Parent>>::Value,
<OwnerField as ReadableFieldInfo<Parent>>::Meta,
> + Copy
+ 'static,
<OwnerField as ReadableFieldInfo<Parent>>::Meta: Comparable + crate::Nullability + 'static,
ForeignKey: crate::Compatible<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
Option<ForeignKey>: RelationForeignKeyRef<<OwnerField as ReadableFieldInfo<Parent>>::Value>,
MorphField: MorphTypeFieldInfo<Child>,
crate::BinaryType<
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
>: crate::PredicateType,
{
fn as_morph<Target>(self) -> OptionalQuery<Target>
where
Target: Qrafting + FromRow + ModelKey + 'static,
{
self.into_built().as_morph::<Target>()
}
}
impl<'a, Child: Draftable, ForeignField, MorphField> MorphToMut
for BuiltMorphToMut<'a, Child, ForeignField, MorphField>
where
Child: Qrafting + FromRow + Draftable,
ForeignField: Copy,
MorphField: MorphTypeFieldInfo<Child>,
{
type Child = Child;
fn associate<'b, Parent>(self, parent: &Parent) -> <Self::Child as Draftable>::Draft<'b>
where
Parent: Qrafting + FromRow + ModelKey + 'static,
Self: 'b,
{
let type_id = TypeId::of::<Parent>();
let target = self
.targets
.iter()
.find(|target| target.type_id == type_id)
.expect("morph_to target not registered");
let mut dirty_fields = (target.assign)(self.foreign_key, self.child, parent as &dyn Any);
self.morph_type.assign(self.child, target.morph_name);
dirty_fields.push(self.morph_type.dirty_field());
Child::draft_mark_many(self.child, &dirty_fields)
}
}
impl<'a, Child: Draftable, ForeignKey, ForeignMeta, MorphField, Parent, OwnerField> MorphToMut
for MorphToMutTargetBuilder<
'a,
Child,
PersistedField<Child, ForeignKey, ForeignMeta, RequiredField>,
MorphField,
Parent,
OwnerField,
>
where
Child: Qrafting + FromRow + Draftable,
Parent: Qrafting + FromRow + 'static,
ForeignMeta: crate::TypeMeta,
OwnerField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<OwnerField as ReadableFieldInfo<Parent>>::Value,
<OwnerField as ReadableFieldInfo<Parent>>::Meta,
> + Copy
+ 'static,
<OwnerField as ReadableFieldInfo<Parent>>::Meta: Comparable + crate::Nullability + 'static,
ForeignKey: crate::Compatible<<OwnerField as ReadableFieldInfo<Parent>>::Meta>
+ RelationForeignKeyRef<<OwnerField as ReadableFieldInfo<Parent>>::Value>,
MorphField: MorphTypeFieldInfo<Child>,
crate::BinaryType<
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
>: crate::PredicateType,
{
type Child = Child;
fn associate<'b, Target>(self, parent: &Target) -> <Self::Child as Draftable>::Draft<'b>
where
Target: Qrafting + FromRow + ModelKey + 'static,
Self: 'b,
{
self.into_built().associate(parent)
}
}
impl<'a, Child: Draftable, ForeignKey, ForeignMeta, MorphField, Parent, OwnerField> MorphToMut
for MorphToMutTargetBuilder<
'a,
Child,
PersistedField<Child, Option<ForeignKey>, ForeignMeta, NullableField>,
MorphField,
Parent,
OwnerField,
>
where
Child: Qrafting + FromRow + Draftable,
Parent: Qrafting + FromRow + 'static,
ForeignMeta: crate::TypeMeta,
OwnerField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<OwnerField as ReadableFieldInfo<Parent>>::Value,
<OwnerField as ReadableFieldInfo<Parent>>::Meta,
> + Copy
+ 'static,
<OwnerField as ReadableFieldInfo<Parent>>::Meta: Comparable + crate::Nullability + 'static,
ForeignKey: crate::Compatible<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
Option<ForeignKey>: RelationForeignKeyRef<<OwnerField as ReadableFieldInfo<Parent>>::Value>,
MorphField: MorphTypeFieldInfo<Child>,
crate::BinaryType<
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
crate::NullOf<<OwnerField as ReadableFieldInfo<Parent>>::Meta>,
>: crate::PredicateType,
{
type Child = Child;
fn associate<'b, Target>(self, parent: &Target) -> <Self::Child as Draftable>::Draft<'b>
where
Target: Qrafting + FromRow + ModelKey + 'static,
Self: 'b,
{
self.into_built().associate(parent)
}
}
impl<'a, Parent, Pivot, ParentMeta, Related> BelongsToMany<Related>
for BelongsToManyRelatedKeyBuilder<
'a,
Parent,
Pivot,
ParentMeta,
<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta,
>
where
Parent: Qrafting + ModelKey,
Pivot: Qrafting,
Related: Qrafting + FromRow + ModelKey,
<Parent as ModelKey>::Key: crate::DefaultMeta,
<Parent as ModelKey>::Key: crate::Compatible<ParentMeta> + Clone,
<Related as ModelKey>::Key: crate::DefaultMeta + Clone,
<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta: Comparable + crate::Nullability,
ParentMeta: Comparable + crate::Nullability + crate::TypeMeta,
crate::BinaryType<crate::NullOf<ParentMeta>, crate::NullOf<ParentMeta>>: crate::PredicateType,
crate::BinaryType<
crate::NullOf<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
crate::NullOf<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
>: crate::PredicateType,
{
type Pivot = Pivot;
type ActionState =
BelongsToManyActionState<Related, Pivot, ParentMeta, <Parent as ModelKey>::Key>;
fn into_query(self) -> QueryOf<Related> {
build_belongs_to_many_query(
self.parent,
self.pivot_table,
self.parent_key,
self.related_key,
model_key_field::<Parent>(),
)
}
fn into_action_state(self) -> Self::ActionState {
BelongsToManyActionState {
pivot_table: self.pivot_table,
parent_column: self.parent_key,
related_column: self.related_key,
parent_key: <Parent as ModelKey>::__qraft_key(self.parent).clone(),
}
}
}
impl<'a, Parent, Pivot, ParentMeta, LocalField, Related> BelongsToMany<Related>
for BuiltBelongsToMany<
'a,
Parent,
Pivot,
ParentMeta,
<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta,
LocalField,
>
where
Parent: Qrafting,
Pivot: Qrafting,
Related: Qrafting + FromRow + ModelKey,
LocalField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<LocalField as ReadableFieldInfo<Parent>>::Value,
<LocalField as ReadableFieldInfo<Parent>>::Meta,
> + Copy,
<LocalField as ReadableFieldInfo<Parent>>::Value: crate::Compatible<ParentMeta> + Clone,
<Related as ModelKey>::Key: crate::DefaultMeta + Clone,
<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta: Comparable + crate::Nullability,
ParentMeta: Comparable + crate::Nullability + crate::TypeMeta,
crate::BinaryType<crate::NullOf<ParentMeta>, crate::NullOf<ParentMeta>>: crate::PredicateType,
crate::BinaryType<
crate::NullOf<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
crate::NullOf<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
>: crate::PredicateType,
{
type Pivot = Pivot;
type ActionState = BelongsToManyActionState<
Related,
Pivot,
ParentMeta,
<LocalField as ReadableFieldInfo<Parent>>::Value,
>;
fn into_query(self) -> QueryOf<Related> {
build_belongs_to_many_query(
self.parent,
self.pivot_table,
self.parent_key,
self.related_key,
self.local_key,
)
}
fn into_action_state(self) -> Self::ActionState {
BelongsToManyActionState {
pivot_table: self.pivot_table,
parent_column: self.parent_key,
related_column: self.related_key,
parent_key: (self.local_key.getter())(self.parent).clone(),
}
}
}
impl<'a, Parent, Pivot, ParentMeta, Related> MorphToMany<Related>
for MorphToManyRelatedKeyBuilder<
'a,
Parent,
Pivot,
ParentMeta,
<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta,
>
where
Parent: Qrafting + ModelKey + MorphName,
Pivot: Qrafting,
Related: Qrafting + FromRow + ModelKey,
<Parent as ModelKey>::Key: crate::DefaultMeta,
<Parent as ModelKey>::Key: crate::Compatible<ParentMeta> + Clone,
<Related as ModelKey>::Key: crate::DefaultMeta + Clone,
<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta: Comparable + crate::Nullability,
ParentMeta: Comparable + crate::Nullability + crate::TypeMeta,
&'static str: crate::LowerCompatible<crate::Text>,
crate::BinaryType<crate::NullOf<ParentMeta>, crate::NullOf<ParentMeta>>: crate::PredicateType,
crate::BinaryType<
crate::NullOf<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
crate::NullOf<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
>: crate::PredicateType,
crate::BinaryType<crate::NullOf<crate::Text>, crate::NullOf<crate::Text>>: crate::PredicateType,
{
type Pivot = Pivot;
type ActionState =
MorphToManyActionState<Related, Pivot, ParentMeta, <Parent as ModelKey>::Key>;
fn into_query(self) -> QueryOf<Related> {
build_morph_to_many_query(
self.parent,
MorphToManyQueryParts {
pivot_table: self.pivot_table,
parent_key: self.parent_key,
morph_type: self.morph_type,
related_key: self.related_key,
local_key: model_key_field::<Parent>(),
morph_name: self
.morph_name
.unwrap_or_else(<Parent as MorphName>::morph_name),
},
)
}
fn into_action_state(self) -> Self::ActionState {
MorphToManyActionState {
pivot_table: self.pivot_table,
parent_column: self.parent_key,
type_column: self.morph_type,
related_column: self.related_key,
parent_key: <Parent as ModelKey>::__qraft_key(self.parent).clone(),
morph_name: self
.morph_name
.unwrap_or_else(<Parent as MorphName>::morph_name),
}
}
}
impl<'a, Parent, Pivot, ParentMeta, LocalField, Related> MorphToMany<Related>
for BuiltMorphToMany<
'a,
Parent,
Pivot,
ParentMeta,
<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta,
LocalField,
>
where
Parent: Qrafting + MorphName,
Pivot: Qrafting,
Related: Qrafting + FromRow + ModelKey,
LocalField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<LocalField as ReadableFieldInfo<Parent>>::Value,
<LocalField as ReadableFieldInfo<Parent>>::Meta,
> + Copy,
<LocalField as ReadableFieldInfo<Parent>>::Value: crate::Compatible<ParentMeta> + Clone,
<Related as ModelKey>::Key: crate::DefaultMeta + Clone,
<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta: Comparable + crate::Nullability,
ParentMeta: Comparable + crate::Nullability + crate::TypeMeta,
&'static str: crate::LowerCompatible<crate::Text>,
crate::BinaryType<crate::NullOf<ParentMeta>, crate::NullOf<ParentMeta>>: crate::PredicateType,
crate::BinaryType<
crate::NullOf<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
crate::NullOf<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
>: crate::PredicateType,
crate::BinaryType<crate::NullOf<crate::Text>, crate::NullOf<crate::Text>>: crate::PredicateType,
{
type Pivot = Pivot;
type ActionState = MorphToManyActionState<
Related,
Pivot,
ParentMeta,
<LocalField as ReadableFieldInfo<Parent>>::Value,
>;
fn into_query(self) -> QueryOf<Related> {
build_morph_to_many_query(
self.parent,
MorphToManyQueryParts {
pivot_table: self.pivot_table,
parent_key: self.parent_key,
morph_type: self.morph_type,
related_key: self.related_key,
local_key: self.local_key,
morph_name: self
.morph_name
.unwrap_or_else(<Parent as MorphName>::morph_name),
},
)
}
fn into_action_state(self) -> Self::ActionState {
MorphToManyActionState {
pivot_table: self.pivot_table,
parent_column: self.parent_key,
type_column: self.morph_type,
related_column: self.related_key,
parent_key: (self.local_key.getter())(self.parent).clone(),
morph_name: self
.morph_name
.unwrap_or_else(<Parent as MorphName>::morph_name),
}
}
}
impl<'a, Parent, Pivot, ParentMeta, Related> MorphToMany<Related>
for MorphedByManyRelatedKeyBuilder<
'a,
Parent,
Pivot,
ParentMeta,
<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta,
>
where
Parent: Qrafting + ModelKey,
Pivot: Qrafting,
Related: Qrafting + FromRow + ModelKey + MorphName,
<Parent as ModelKey>::Key: crate::DefaultMeta,
<Parent as ModelKey>::Key: crate::Compatible<ParentMeta> + Clone,
<Related as ModelKey>::Key: crate::DefaultMeta + Clone,
<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta: Comparable + crate::Nullability,
ParentMeta: Comparable + crate::Nullability + crate::TypeMeta,
&'static str: crate::LowerCompatible<crate::Text>,
crate::BinaryType<crate::NullOf<ParentMeta>, crate::NullOf<ParentMeta>>: crate::PredicateType,
crate::BinaryType<
crate::NullOf<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
crate::NullOf<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
>: crate::PredicateType,
crate::BinaryType<crate::NullOf<crate::Text>, crate::NullOf<crate::Text>>: crate::PredicateType,
{
type Pivot = Pivot;
type ActionState =
MorphToManyActionState<Related, Pivot, ParentMeta, <Parent as ModelKey>::Key>;
fn into_query(self) -> QueryOf<Related> {
build_morph_to_many_query(
self.parent,
MorphToManyQueryParts {
pivot_table: self.pivot_table,
parent_key: self.parent_key,
morph_type: self.morph_type,
related_key: self.related_key,
local_key: model_key_field::<Parent>(),
morph_name: self
.morph_name
.unwrap_or_else(<Related as MorphName>::morph_name),
},
)
}
fn into_action_state(self) -> Self::ActionState {
MorphToManyActionState {
pivot_table: self.pivot_table,
parent_column: self.parent_key,
type_column: self.morph_type,
related_column: self.related_key,
parent_key: <Parent as ModelKey>::__qraft_key(self.parent).clone(),
morph_name: self
.morph_name
.unwrap_or_else(<Related as MorphName>::morph_name),
}
}
}
impl<'a, Parent, Pivot, ParentMeta, LocalField, Related> MorphToMany<Related>
for BuiltMorphedByMany<
'a,
Parent,
Pivot,
ParentMeta,
<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta,
LocalField,
>
where
Parent: Qrafting,
Pivot: Qrafting,
Related: Qrafting + FromRow + ModelKey + MorphName,
LocalField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<LocalField as ReadableFieldInfo<Parent>>::Value,
<LocalField as ReadableFieldInfo<Parent>>::Meta,
> + Copy,
<LocalField as ReadableFieldInfo<Parent>>::Value: crate::Compatible<ParentMeta> + Clone,
<Related as ModelKey>::Key: crate::DefaultMeta + Clone,
<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta: Comparable + crate::Nullability,
ParentMeta: Comparable + crate::Nullability + crate::TypeMeta,
&'static str: crate::LowerCompatible<crate::Text>,
crate::BinaryType<crate::NullOf<ParentMeta>, crate::NullOf<ParentMeta>>: crate::PredicateType,
crate::BinaryType<
crate::NullOf<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
crate::NullOf<<<Related as ModelKey>::Key as crate::DefaultMeta>::Meta>,
>: crate::PredicateType,
crate::BinaryType<crate::NullOf<crate::Text>, crate::NullOf<crate::Text>>: crate::PredicateType,
{
type Pivot = Pivot;
type ActionState = MorphToManyActionState<
Related,
Pivot,
ParentMeta,
<LocalField as ReadableFieldInfo<Parent>>::Value,
>;
fn into_query(self) -> QueryOf<Related> {
build_morph_to_many_query(
self.parent,
MorphToManyQueryParts {
pivot_table: self.pivot_table,
parent_key: self.parent_key,
morph_type: self.morph_type,
related_key: self.related_key,
local_key: self.local_key,
morph_name: self
.morph_name
.unwrap_or_else(<Related as MorphName>::morph_name),
},
)
}
fn into_action_state(self) -> Self::ActionState {
MorphToManyActionState {
pivot_table: self.pivot_table,
parent_column: self.parent_key,
type_column: self.morph_type,
related_column: self.related_key,
parent_key: (self.local_key.getter())(self.parent).clone(),
morph_name: self
.morph_name
.unwrap_or_else(<Related as MorphName>::morph_name),
}
}
}
impl<'a, Parent, Child, ForeignField> HasMany<Child>
for HasManyFieldsBuilder<'a, Parent, Child, ForeignField>
where
Parent: ModelKey,
Child: Qrafting + FromRow + Draftable,
<Parent as ModelKey>::Key: crate::DefaultMeta,
ForeignField: ReadableFieldInfo<Child>
+ ReadableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + WritableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + Copy,
<ForeignField as ReadableFieldInfo<Child>>::Meta: Comparable + crate::Nullability,
<Parent as ModelKey>::Key: crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
<ForeignField as ReadableFieldInfo<Child>>::Value: RelationForeignKeyRef<<Parent as ModelKey>::Key>
+ crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
crate::BinaryType<
crate::NullOf<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
crate::NullOf<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
>: crate::PredicateType,
{
fn into_query(self) -> QueryOf<Child> {
self.local_key(model_key_field::<Parent>()).into_query()
}
fn associate<'b>(self, child: &'b mut Child) -> <Child as Draftable>::Draft<'b>
where
Child: Draftable,
{
self.local_key(model_key_field::<Parent>()).associate(child)
}
fn create<V>(self, values: V) -> Insert<Child>
where
Child: Qrafting,
V: Insertable<Child>,
{
self.local_key(model_key_field::<Parent>()).create(values)
}
}
impl<'a, Parent, Child, ForeignField, LocalField> HasMany<Child>
for BuiltHasMany<'a, Parent, Child, ForeignField, LocalField>
where
Child: Qrafting + FromRow + Draftable,
ForeignField: ReadableFieldInfo<Child>
+ ReadableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + WritableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + Copy,
LocalField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<LocalField as ReadableFieldInfo<Parent>>::Value,
<LocalField as ReadableFieldInfo<Parent>>::Meta,
> + Copy,
<ForeignField as ReadableFieldInfo<Child>>::Meta: Comparable + crate::Nullability,
<LocalField as ReadableFieldInfo<Parent>>::Meta: crate::TypeMeta,
<LocalField as ReadableFieldInfo<Parent>>::Value:
crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
<ForeignField as ReadableFieldInfo<Child>>::Value: RelationForeignKeyRef<<LocalField as ReadableFieldInfo<Parent>>::Value>
+ crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
crate::BinaryType<
crate::NullOf<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
crate::NullOf<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
>: crate::PredicateType,
{
fn into_query(self) -> QueryOf<Child> {
<Child as Qrafting>::__qraft_query().filter(
self.foreign_key
.column()
.eq((self.local_key.getter())(self.parent)),
)
}
fn associate<'b>(self, child: &'b mut Child) -> <Child as Draftable>::Draft<'b>
where
Child: Draftable,
{
(self.foreign_key.setter())(
child,
<ForeignField as ReadableFieldInfo<Child>>::Value::from_relation_key_ref((self
.local_key
.getter())(
self.parent
)),
);
Child::draft_mark(child, self.foreign_key.dirty_field())
}
fn create<V>(self, values: V) -> Insert<Child>
where
Child: Qrafting,
V: Insertable<Child>,
{
crate::insert_into(crate::query::Table::new(Child::TABLE)).values(InjectRelationValues {
parent: self.parent,
values,
foreign_key: self.foreign_key,
local_key: self.local_key,
})
}
}
impl<'a, Parent, Child, ForeignField> HasOne<Child>
for HasOneFieldsBuilder<'a, Parent, Child, ForeignField>
where
Parent: ModelKey,
Child: Qrafting + FromRow + Draftable,
<Parent as ModelKey>::Key: crate::DefaultMeta,
ForeignField: ReadableFieldInfo<Child>
+ ReadableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + WritableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + Copy,
<ForeignField as ReadableFieldInfo<Child>>::Meta: Comparable + crate::Nullability,
<Parent as ModelKey>::Key: crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
<ForeignField as ReadableFieldInfo<Child>>::Value: RelationForeignKeyRef<<Parent as ModelKey>::Key>
+ crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
crate::BinaryType<
crate::NullOf<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
crate::NullOf<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
>: crate::PredicateType,
{
fn into_query(self) -> QueryOf<Child> {
self.local_key(model_key_field::<Parent>()).into_query()
}
fn associate<'b>(self, child: &'b mut Child) -> <Child as Draftable>::Draft<'b>
where
Child: Draftable,
{
self.local_key(model_key_field::<Parent>()).associate(child)
}
fn create<V>(self, values: V) -> Insert<Child>
where
Child: Qrafting,
V: Insertable<Child>,
{
self.local_key(model_key_field::<Parent>()).create(values)
}
}
impl<'a, Parent, Child, ForeignField, LocalField> HasOne<Child>
for BuiltHasOne<'a, Parent, Child, ForeignField, LocalField>
where
Child: Qrafting + FromRow + Draftable,
ForeignField: ReadableFieldInfo<Child>
+ ReadableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + WritableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + Copy,
LocalField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<LocalField as ReadableFieldInfo<Parent>>::Value,
<LocalField as ReadableFieldInfo<Parent>>::Meta,
> + Copy,
<ForeignField as ReadableFieldInfo<Child>>::Meta: Comparable + crate::Nullability,
<LocalField as ReadableFieldInfo<Parent>>::Meta: crate::TypeMeta,
<LocalField as ReadableFieldInfo<Parent>>::Value:
crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
<ForeignField as ReadableFieldInfo<Child>>::Value: RelationForeignKeyRef<<LocalField as ReadableFieldInfo<Parent>>::Value>
+ crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
crate::BinaryType<
crate::NullOf<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
crate::NullOf<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
>: crate::PredicateType,
{
fn into_query(self) -> QueryOf<Child> {
<Child as Qrafting>::__qraft_query()
.filter(
self.foreign_key
.column()
.eq((self.local_key.getter())(self.parent)),
)
.limit(1_i64)
}
fn associate<'b>(self, child: &'b mut Child) -> <Child as Draftable>::Draft<'b>
where
Child: Draftable,
{
(self.foreign_key.setter())(
child,
<ForeignField as ReadableFieldInfo<Child>>::Value::from_relation_key_ref((self
.local_key
.getter())(
self.parent
)),
);
Child::draft_mark(child, self.foreign_key.dirty_field())
}
fn create<V>(self, values: V) -> Insert<Child>
where
Child: Qrafting,
V: Insertable<Child>,
{
crate::insert_into(crate::query::Table::new(Child::TABLE)).values(InjectRelationValues {
parent: self.parent,
values,
foreign_key: self.foreign_key,
local_key: self.local_key,
})
}
}
impl<'a, Parent, Child, ForeignField, MorphField> MorphMany<Child>
for MorphManyTypeBuilder<'a, Parent, Child, ForeignField, MorphField>
where
Parent: ModelKey + MorphName,
Child: Qrafting + FromRow + Draftable,
<Parent as ModelKey>::Key: crate::DefaultMeta,
ForeignField: ReadableFieldInfo<Child>
+ ReadableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + WritableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + Copy,
MorphField: MorphTypeFieldInfo<Child>,
<ForeignField as ReadableFieldInfo<Child>>::Meta: Comparable + crate::Nullability,
<Parent as ModelKey>::Key: crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
<ForeignField as ReadableFieldInfo<Child>>::Value: RelationForeignKeyRef<<Parent as ModelKey>::Key>
+ crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
crate::BinaryType<
crate::NullOf<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
crate::NullOf<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
>: crate::PredicateType,
{
fn into_query(self) -> QueryOf<Child> {
self.morph_name(<Parent as MorphName>::morph_name())
.into_query()
}
fn associate<'b>(self, child: &'b mut Child) -> <Child as Draftable>::Draft<'b>
where
Child: Draftable,
{
self.morph_name(<Parent as MorphName>::morph_name())
.associate(child)
}
fn create<V>(self, values: V) -> Insert<Child>
where
Child: Qrafting,
V: Insertable<Child>,
{
self.morph_name(<Parent as MorphName>::morph_name())
.create(values)
}
}
impl<'a, Parent, Child, ForeignField, MorphField, LocalField> MorphMany<Child>
for BuiltMorphMany<'a, Parent, Child, ForeignField, MorphField, LocalField>
where
Child: Qrafting + FromRow + Draftable,
ForeignField: ReadableFieldInfo<Child>
+ ReadableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + WritableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + Copy,
LocalField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<LocalField as ReadableFieldInfo<Parent>>::Value,
<LocalField as ReadableFieldInfo<Parent>>::Meta,
> + Copy,
MorphField: MorphTypeFieldInfo<Child>,
<ForeignField as ReadableFieldInfo<Child>>::Meta: Comparable + crate::Nullability,
<LocalField as ReadableFieldInfo<Parent>>::Value:
crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
<ForeignField as ReadableFieldInfo<Child>>::Value: RelationForeignKeyRef<<LocalField as ReadableFieldInfo<Parent>>::Value>
+ crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
crate::BinaryType<
crate::NullOf<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
crate::NullOf<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
>: crate::PredicateType,
{
fn into_query(self) -> QueryOf<Child> {
self.morph_type.filter_query(
<Child as Qrafting>::__qraft_query().filter(
self.foreign_key
.column()
.eq((self.local_key.getter())(self.parent)),
),
self.morph_name,
)
}
fn associate<'b>(self, child: &'b mut Child) -> <Child as Draftable>::Draft<'b>
where
Child: Draftable,
{
(self.foreign_key.setter())(
child,
<ForeignField as ReadableFieldInfo<Child>>::Value::from_relation_key_ref((self
.local_key
.getter())(
self.parent
)),
);
self.morph_type.assign(child, self.morph_name);
Child::draft_mark_many(
child,
&[
self.foreign_key.dirty_field(),
self.morph_type.dirty_field(),
],
)
}
fn create<V>(self, values: V) -> Insert<Child>
where
Child: Qrafting,
V: Insertable<Child>,
{
crate::insert_into(crate::query::Table::new(Child::TABLE)).values(
InjectMorphRelationValues {
parent: self.parent,
values,
foreign_key: self.foreign_key,
local_key: self.local_key,
morph_type: self.morph_type,
morph_name: self.morph_name,
},
)
}
}
impl<'a, Parent, Child, ForeignField, MorphField> MorphOne<Child>
for MorphOneTypeBuilder<'a, Parent, Child, ForeignField, MorphField>
where
Parent: ModelKey + MorphName,
Child: Qrafting + FromRow + Draftable,
<Parent as ModelKey>::Key: crate::DefaultMeta,
ForeignField: ReadableFieldInfo<Child>
+ ReadableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + WritableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + Copy,
MorphField: MorphTypeFieldInfo<Child>,
<ForeignField as ReadableFieldInfo<Child>>::Meta: Comparable + crate::Nullability,
<Parent as ModelKey>::Key: crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
<ForeignField as ReadableFieldInfo<Child>>::Value: RelationForeignKeyRef<<Parent as ModelKey>::Key>
+ crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
crate::BinaryType<
crate::NullOf<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
crate::NullOf<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
>: crate::PredicateType,
{
fn into_query(self) -> QueryOf<Child> {
self.morph_name(<Parent as MorphName>::morph_name())
.into_query()
}
fn associate<'b>(self, child: &'b mut Child) -> <Child as Draftable>::Draft<'b>
where
Child: Draftable,
{
self.morph_name(<Parent as MorphName>::morph_name())
.associate(child)
}
fn create<V>(self, values: V) -> Insert<Child>
where
Child: Qrafting,
V: Insertable<Child>,
{
self.morph_name(<Parent as MorphName>::morph_name())
.create(values)
}
}
impl<'a, Parent, Child, ForeignField, MorphField, LocalField> MorphOne<Child>
for BuiltMorphOne<'a, Parent, Child, ForeignField, MorphField, LocalField>
where
Child: Qrafting + FromRow + Draftable,
ForeignField: ReadableFieldInfo<Child>
+ ReadableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + WritableField<
Child,
<ForeignField as ReadableFieldInfo<Child>>::Value,
<ForeignField as ReadableFieldInfo<Child>>::Meta,
> + Copy,
LocalField: ReadableFieldInfo<Parent>
+ ReadableField<
Parent,
<LocalField as ReadableFieldInfo<Parent>>::Value,
<LocalField as ReadableFieldInfo<Parent>>::Meta,
> + Copy,
MorphField: MorphTypeFieldInfo<Child>,
<ForeignField as ReadableFieldInfo<Child>>::Meta: Comparable + crate::Nullability,
<LocalField as ReadableFieldInfo<Parent>>::Value:
crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
<ForeignField as ReadableFieldInfo<Child>>::Value: RelationForeignKeyRef<<LocalField as ReadableFieldInfo<Parent>>::Value>
+ crate::Compatible<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
crate::BinaryType<
crate::NullOf<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
crate::NullOf<<ForeignField as ReadableFieldInfo<Child>>::Meta>,
>: crate::PredicateType,
{
fn into_query(self) -> QueryOf<Child> {
self.morph_type
.filter_query(
<Child as Qrafting>::__qraft_query().filter(
self.foreign_key
.column()
.eq((self.local_key.getter())(self.parent)),
),
self.morph_name,
)
.limit(1_i64)
}
fn associate<'b>(self, child: &'b mut Child) -> <Child as Draftable>::Draft<'b>
where
Child: Draftable,
{
(self.foreign_key.setter())(
child,
<ForeignField as ReadableFieldInfo<Child>>::Value::from_relation_key_ref((self
.local_key
.getter())(
self.parent
)),
);
self.morph_type.assign(child, self.morph_name);
Child::draft_mark_many(
child,
&[
self.foreign_key.dirty_field(),
self.morph_type.dirty_field(),
],
)
}
fn create<V>(self, values: V) -> Insert<Child>
where
Child: Qrafting,
V: Insertable<Child>,
{
crate::insert_into(crate::query::Table::new(Child::TABLE)).values(
InjectMorphRelationValues {
parent: self.parent,
values,
foreign_key: self.foreign_key,
local_key: self.local_key,
morph_type: self.morph_type,
morph_name: self.morph_name,
},
)
}
}
impl<Relation, Child, SortMeta> HasOne<Child> for MaxByOfMany<Relation, Child, SortMeta>
where
Relation: HasMany<Child>,
Child: Qrafting + FromRow + Draftable + ModelKey,
SortMeta: Orderable,
<Child as ModelKey>::Key: crate::DefaultMeta,
ModelField<
Child,
<Child as ModelKey>::Key,
<<Child as ModelKey>::Key as crate::DefaultMeta>::Meta,
>: PrimaryKeyOrderFields<Child>,
{
fn into_query(self) -> QueryOf<Child> {
model_key_field::<Child>()
.order_max(self.relation.into_query(), self.column)
.limit(1_i64)
}
fn associate<'a>(self, child: &'a mut Child) -> <Child as Draftable>::Draft<'a>
where
Child: Draftable,
{
self.relation.associate(child)
}
fn create<V>(self, values: V) -> Insert<Child>
where
Child: Qrafting,
V: Insertable<Child>,
{
self.relation.create(values)
}
}
impl<Relation, Child, SortMeta> HasOne<Child> for MinByOfMany<Relation, Child, SortMeta>
where
Relation: HasMany<Child>,
Child: Qrafting + FromRow + Draftable + ModelKey,
SortMeta: Orderable,
<Child as ModelKey>::Key: crate::DefaultMeta,
ModelField<
Child,
<Child as ModelKey>::Key,
<<Child as ModelKey>::Key as crate::DefaultMeta>::Meta,
>: PrimaryKeyOrderFields<Child>,
{
fn into_query(self) -> QueryOf<Child> {
model_key_field::<Child>()
.order_min(self.relation.into_query(), self.column)
.limit(1_i64)
}
fn associate<'a>(self, child: &'a mut Child) -> <Child as Draftable>::Draft<'a>
where
Child: Draftable,
{
self.relation.associate(child)
}
fn create<V>(self, values: V) -> Insert<Child>
where
Child: Qrafting,
V: Insertable<Child>,
{
self.relation.create(values)
}
}
impl<'a, Child, Parent, ForeignKey, ForeignMeta, OwnerKey, OwnerMeta, OwnerField> BelongsTo<Parent>
for BuiltBelongsToMut<
'a,
Child,
Parent,
ForeignKey,
ForeignMeta,
OwnerKey,
OwnerMeta,
OwnerField,
>
where
Child: Draftable,
Parent: Qrafting + FromRow,
ForeignMeta: crate::TypeMeta,
OwnerMeta: Comparable + crate::Nullability,
OwnerField: ReadableField<Parent, OwnerKey, OwnerMeta>,
ForeignKey: crate::Compatible<OwnerMeta>,
crate::BinaryType<crate::NullOf<OwnerMeta>, crate::NullOf<OwnerMeta>>: crate::PredicateType,
{
fn into_query(self) -> QueryOf<Parent> {
<Parent as Qrafting>::__qraft_query().filter(
self.owner_key
.column()
.eq((self.foreign_key.getter())(self.child)),
)
}
}
impl<'a, Child, Parent, ForeignKey, ForeignMeta> BelongsTo<Parent>
for RequiredBelongsToMutBuilder<'a, Child, ForeignKey, ForeignMeta>
where
Child: Draftable,
Parent: Qrafting + FromRow + ModelKey,
<Parent as ModelKey>::Key: crate::DefaultMeta,
ForeignMeta: crate::TypeMeta,
ForeignKey: RelationForeignKeyRef<<Parent as ModelKey>::Key>
+ crate::Compatible<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta: Comparable + crate::Nullability,
crate::BinaryType<
crate::NullOf<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
crate::NullOf<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
>: crate::PredicateType,
{
fn into_query(self) -> QueryOf<Parent> {
self.owner_model_key::<Parent>().into_query()
}
}
impl<'a, Child, Parent, ForeignKey, ForeignMeta, OwnerKey, OwnerMeta, OwnerField>
BelongsToMut<Parent>
for BuiltBelongsToMut<
'a,
Child,
Parent,
ForeignKey,
ForeignMeta,
OwnerKey,
OwnerMeta,
OwnerField,
>
where
Child: Draftable,
Parent: Qrafting + FromRow,
ForeignMeta: crate::TypeMeta,
OwnerField: ReadableField<Parent, OwnerKey, OwnerMeta>,
ForeignKey: RelationForeignKeyRef<OwnerKey> + crate::Compatible<OwnerMeta>,
OwnerMeta: Comparable + crate::Nullability,
crate::BinaryType<crate::NullOf<OwnerMeta>, crate::NullOf<OwnerMeta>>: crate::PredicateType,
{
type Child = Child;
fn associate<'b>(self, parent: &Parent) -> <Self::Child as Draftable>::Draft<'b>
where
Self: 'b,
{
(self.foreign_key.setter())(
self.child,
ForeignKey::from_relation_key_ref((self.owner_key.getter())(parent)),
);
Child::draft_mark(self.child, self.foreign_key.dirty_field())
}
}
impl<'a, Child, Parent, ForeignKey, ForeignMeta> BelongsToMut<Parent>
for RequiredBelongsToMutBuilder<'a, Child, ForeignKey, ForeignMeta>
where
Child: Draftable,
Parent: Qrafting + FromRow + ModelKey,
<Parent as ModelKey>::Key: crate::DefaultMeta,
ForeignMeta: crate::TypeMeta,
ForeignKey: RelationForeignKeyRef<<Parent as ModelKey>::Key>
+ crate::Compatible<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta: Comparable + crate::Nullability,
crate::BinaryType<
crate::NullOf<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
crate::NullOf<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
>: crate::PredicateType,
{
type Child = Child;
fn associate<'b>(self, parent: &Parent) -> <Self::Child as Draftable>::Draft<'b>
where
Self: 'b,
{
(self.foreign_key.setter())(
self.child,
ForeignKey::from_relation_key_ref(<Parent as ModelKey>::__qraft_key(parent)),
);
Child::draft_mark(self.child, self.foreign_key.dirty_field())
}
}
impl<'a, Child, Parent, ForeignKey, ForeignMeta, OwnerKey, OwnerMeta, OwnerField>
NullableBelongsTo<Parent>
for BuiltNullableBelongsToMut<
'a,
Child,
Parent,
ForeignKey,
ForeignMeta,
OwnerKey,
OwnerMeta,
OwnerField,
>
where
Child: Draftable,
Parent: Qrafting + FromRow,
ForeignMeta: crate::TypeMeta,
OwnerMeta: Comparable + crate::Nullability,
OwnerField: ReadableField<Parent, OwnerKey, OwnerMeta>,
ForeignKey: crate::Compatible<OwnerMeta>,
crate::BinaryType<crate::NullOf<OwnerMeta>, crate::NullOf<OwnerMeta>>: crate::PredicateType,
{
fn into_optional_query(self) -> OptionalQuery<Parent> {
OptionalQuery::new(
((self.foreign_key.getter())(self.child))
.as_ref()
.map(|value| {
<Parent as Qrafting>::__qraft_query().filter(self.owner_key.column().eq(value))
}),
)
}
}
impl<'a, Child, Parent, ForeignKey, ForeignMeta> NullableBelongsTo<Parent>
for NullableBelongsToMutBuilderImpl<'a, Child, ForeignKey, ForeignMeta>
where
Child: Draftable,
Parent: Qrafting + FromRow + ModelKey,
<Parent as ModelKey>::Key: crate::DefaultMeta,
ForeignMeta: crate::TypeMeta,
ForeignKey: RelationForeignKeyRef<<Parent as ModelKey>::Key>
+ crate::Compatible<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta: Comparable + crate::Nullability,
crate::BinaryType<
crate::NullOf<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
crate::NullOf<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
>: crate::PredicateType,
{
fn into_optional_query(self) -> OptionalQuery<Parent> {
self.owner_model_key::<Parent>().into_optional_query()
}
}
impl<'a, Child, Parent, ForeignKey, ForeignMeta, OwnerKey, OwnerMeta, OwnerField>
NullableBelongsToMut<Parent>
for BuiltNullableBelongsToMut<
'a,
Child,
Parent,
ForeignKey,
ForeignMeta,
OwnerKey,
OwnerMeta,
OwnerField,
>
where
Child: Draftable,
Parent: Qrafting + FromRow,
ForeignMeta: crate::TypeMeta,
OwnerMeta: Comparable + crate::Nullability,
OwnerField: ReadableField<Parent, OwnerKey, OwnerMeta>,
ForeignKey: RelationForeignKeyRef<OwnerKey> + crate::Compatible<OwnerMeta>,
crate::BinaryType<crate::NullOf<OwnerMeta>, crate::NullOf<OwnerMeta>>: crate::PredicateType,
{
type Child = Child;
fn associate<'b>(self, parent: &Parent) -> <Self::Child as Draftable>::Draft<'b>
where
Self: 'b,
{
(self.foreign_key.setter())(
self.child,
Some(ForeignKey::from_relation_key_ref(
(self.owner_key.getter())(parent),
)),
);
Child::draft_mark(self.child, self.foreign_key.dirty_field())
}
fn dissociate<'b>(self) -> <Self::Child as Draftable>::Draft<'b>
where
Self: 'b,
{
(self.foreign_key.setter())(self.child, None);
Child::draft_mark(self.child, self.foreign_key.dirty_field())
}
}
impl<'a, Child, Parent, ForeignKey, ForeignMeta> NullableBelongsToMut<Parent>
for NullableBelongsToMutBuilderImpl<'a, Child, ForeignKey, ForeignMeta>
where
Child: Draftable,
Parent: Qrafting + FromRow + ModelKey,
<Parent as ModelKey>::Key: crate::DefaultMeta,
ForeignMeta: crate::TypeMeta,
ForeignKey: RelationForeignKeyRef<<Parent as ModelKey>::Key>
+ crate::Compatible<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta: Comparable + crate::Nullability,
crate::BinaryType<
crate::NullOf<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
crate::NullOf<<<Parent as ModelKey>::Key as crate::DefaultMeta>::Meta>,
>: crate::PredicateType,
{
type Child = Child;
fn associate<'b>(self, parent: &Parent) -> <Self::Child as Draftable>::Draft<'b>
where
Self: 'b,
{
(self.foreign_key.setter())(
self.child,
Some(ForeignKey::from_relation_key_ref(
<Parent as ModelKey>::__qraft_key(parent),
)),
);
Child::draft_mark(self.child, self.foreign_key.dirty_field())
}
fn dissociate<'b>(self) -> <Self::Child as Draftable>::Draft<'b>
where
Self: 'b,
{
(self.foreign_key.setter())(self.child, None);
Child::draft_mark(self.child, self.foreign_key.dirty_field())
}
}