forked from alemi/upub
fix!: eh make it a string
it breaks object.ap() which is used a lot deep, i dont want to have to deal with that now tbh
This commit is contained in:
parent
b89bb87c19
commit
2ca4bfedc4
2 changed files with 11 additions and 8 deletions
|
@ -46,7 +46,7 @@ pub enum Objects {
|
||||||
Table,
|
Table,
|
||||||
Internal,
|
Internal,
|
||||||
Id,
|
Id,
|
||||||
Instance,
|
Domain,
|
||||||
ObjectType,
|
ObjectType,
|
||||||
AttributedTo,
|
AttributedTo,
|
||||||
Name,
|
Name,
|
||||||
|
@ -201,12 +201,12 @@ impl MigrationTrait for Migration {
|
||||||
.auto_increment()
|
.auto_increment()
|
||||||
)
|
)
|
||||||
.col(ColumnDef::new(Objects::Id).string().not_null().unique_key())
|
.col(ColumnDef::new(Objects::Id).string().not_null().unique_key())
|
||||||
.col(ColumnDef::new(Objects::Instance).big_integer().not_null())
|
.col(ColumnDef::new(Objects::Domain).string().not_null())
|
||||||
.foreign_key(
|
.foreign_key(
|
||||||
ForeignKey::create()
|
ForeignKey::create()
|
||||||
.name("fkey-objects-instances")
|
.name("fkey-objects-instances")
|
||||||
.from(Objects::Table, Objects::Instance)
|
.from(Objects::Table, Objects::Domain)
|
||||||
.to(Instances::Table, Instances::Internal)
|
.to(Instances::Table, Instances::Domain)
|
||||||
.on_update(ForeignKeyAction::Cascade)
|
.on_update(ForeignKeyAction::Cascade)
|
||||||
)
|
)
|
||||||
.col(ColumnDef::new(Objects::ObjectType).string().not_null())
|
.col(ColumnDef::new(Objects::ObjectType).string().not_null())
|
||||||
|
|
|
@ -12,7 +12,7 @@ pub struct Model {
|
||||||
pub internal: i64,
|
pub internal: i64,
|
||||||
#[sea_orm(unique)]
|
#[sea_orm(unique)]
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub instance: i64,
|
pub domain: String,
|
||||||
pub object_type: ObjectType,
|
pub object_type: ObjectType,
|
||||||
pub attributed_to: Option<String>,
|
pub attributed_to: Option<String>,
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
|
@ -55,8 +55,8 @@ pub enum Relation {
|
||||||
Hashtags,
|
Hashtags,
|
||||||
#[sea_orm(
|
#[sea_orm(
|
||||||
belongs_to = "super::instance::Entity",
|
belongs_to = "super::instance::Entity",
|
||||||
from = "Column::Instance",
|
from = "Column::Domain",
|
||||||
to = "super::instance::Column::Internal",
|
to = "super::instance::Column::Domain",
|
||||||
on_update = "Cascade",
|
on_update = "Cascade",
|
||||||
on_delete = "NoAction"
|
on_delete = "NoAction"
|
||||||
)]
|
)]
|
||||||
|
@ -160,9 +160,12 @@ impl Entity {
|
||||||
|
|
||||||
impl ActiveModel {
|
impl ActiveModel {
|
||||||
pub fn new(object: &impl apb::Object) -> Result<Self, super::FieldError> {
|
pub fn new(object: &impl apb::Object) -> Result<Self, super::FieldError> {
|
||||||
|
let ap_id = object.id().ok_or(super::FieldError("id"))?.to_string();
|
||||||
|
let domain = crate::server::Context::server(&ap_id);
|
||||||
Ok(ActiveModel {
|
Ok(ActiveModel {
|
||||||
internal: sea_orm::ActiveValue::NotSet,
|
internal: sea_orm::ActiveValue::NotSet,
|
||||||
id: sea_orm::ActiveValue::Set(object.id().ok_or(super::FieldError("id"))?.to_string()),
|
domain: sea_orm::ActiveValue::Set(domain),
|
||||||
|
id: sea_orm::ActiveValue::Set(ap_id),
|
||||||
object_type: sea_orm::ActiveValue::Set(object.object_type().ok_or(super::FieldError("type"))?),
|
object_type: sea_orm::ActiveValue::Set(object.object_type().ok_or(super::FieldError("type"))?),
|
||||||
attributed_to: sea_orm::ActiveValue::Set(object.attributed_to().id()),
|
attributed_to: sea_orm::ActiveValue::Set(object.attributed_to().id()),
|
||||||
name: sea_orm::ActiveValue::Set(object.name().map(|x| x.to_string())),
|
name: sea_orm::ActiveValue::Set(object.name().map(|x| x.to_string())),
|
||||||
|
|
Loading…
Reference in a new issue