Wulf / dsync

Generate rust structs & query functions from diesel schema files
Other
70 stars 13 forks source link

question: `belonging_to` #95

Closed jjangga0214 closed 1 year ago

jjangga0214 commented 1 year ago

It seems belonging_to is not supported. Is this true?

hasezoey commented 1 year ago

i dont know what this is about, please expand your issue with the diesel schema and what you expect as output

jjangga0214 commented 1 year ago

@hasezoey Thank you for the prompt reply :) It was a quick question about whether dsync itself supports it or not. But your answer sounds like dsync does support it, but I missed something, which was what I hoped.

// src/schema.rs
use diesel::sql_types::*;
use diesel::{allow_tables_to_appear_in_same_query, joinable, table};

table! {
    user (id) {
        id -> Uuid
    }
}

table! {
    count (id) {
        id -> Uuid,
        user_id -> Uuid,
    }
}

joinable!(count -> user (user_id));

allow_tables_to_appear_in_same_query!(user, count);
// src/models/count/generated.rs
#[derive(Debug, Serialize, Deserialize, Clone, Queryable, Insertable, AsChangeset, Identifiable, Associations, Selectable)]
#[diesel(table_name=count, primary_key(id), belongs_to(User, foreign_key=user_id))]
pub struct Count {
    pub id: uuid::Uuid,
    pub user_id: uuid::Uuid,
}

I looked around it, and found they are generated well. But I don't know why this is happening.

스크린샷 2023-10-17 오전 1 43 49

Maybe this is not an issue of dsync, but would you help if you know something?

Thank you :)

hasezoey commented 1 year ago

did you import the BelongingToDsl trait? (importing it is required to be able to use its functions)

jjangga0214 commented 1 year ago

Yes, by use diesel::prelude::*;.

hasezoey commented 1 year ago

then i dont think i can help too much, because i have not used that functionality yet, and the dsync tests are not in the best of states (they are currently only hand checked, but not checked that they actually compile and / or run)

jjangga0214 commented 1 year ago

Thank you anyway. Closing the issue.

I left a discussion from diesel's side. Here a link is for folks who may come later.

Wulf commented 11 months ago

@hasezoey thanks for jumping on these issues!

@jjangga0214 I've used the generated belonging_to successfully in the past. Checkout this example from the diesel repo, it might help: https://github.com/diesel-rs/diesel/tree/2.1.x/examples/postgres/relations