problem with relations
moczix opened this issue · comments
part of server_angel.models;
@serializable
@orm
abstract class _User extends Model {
String get username;
String get googleAccountId;
String get googleAccountEmail;
String get picture;
bool get isActive;
bool get isSuspended;
@HasMany()
List<_UserTokens> get userTokens;
}
part of server_angel.models;
@serializable
@orm
abstract class _UserTokens extends Model {
String get token;
DateTime get expiredAt;
@belongsTo
_User get user;
}
then i make a query like this:
UserQuery userQuery = UserQuery();
userQuery.where.googleAccountId.equals(googlePayload.getUserId());
User foundUser = await userQuery.getOne(_executor);`
query log:
SELECT users.id, users.username, users.google_account_id, users.google_account_email, users.picture, users.is_active, users.is_suspended, users.created_at, users.updated_at, a0.id, a0.token, a0.expired_at, a0.user_id, a0.created_at, a0.updated_at FROM users LEFT JOIN (SELECT user_tokens.id, user_tokens.token, user_tokens.expired_at, user_tokens.user_id, user_tokens.created_at, user_tokens.updated_at, a0.id, a0.username, a0.google_account_id, a0.google_account_email, a0.picture, a0.is_active, a0.is_suspended, a0.created_at, a0.updated_at FROM user_tokens LEFT JOIN users a0 ON user_tokens.user_id=a0.id) a0 ON users.id=a0.user_id WHERE users.google_account_id = '321312313213'
and got error:
ERROR: column reference "id" is ambiguous
LINE 1: ...is_suspended, users.created_at, users.updated_at, a0.id, a0....
i got empty table :D just make a fresh call to test
yes yes ;p im using User class :D but wanna report this isue to let you know
Cool, thanks.
But I also mean that even in the schema, use the public class, ex:
@hasMany
List<UserToken> get tokens;
when i remove underscore and use public class and run build runner i got error:
Unsupported operation: Cannot apply relationship to field "user" - dynamic is not assignable to Model.
And its okey, because the public class doesnt exist at the moment of building ;d
Yes, this is why you need the multi-target build setup:
targets:
_standalone:
sources:
- lib/src/models/user.dart
$default:
dependencies:
- :_standalone
sources:
- lib/src/models/user_token.dart
This way, you can have your models in separate files, and the resolver will able to find them at build-time.
build.yaml
documentation:
ah oke oke :D
Are you still experiencing this error, or can I go ahead and close this?
Closing, as I don't believe this error occurs anymore.
For anyone who runs into this in the future, see thread #80.
The underlying cause is upstream: dart-lang/build#2146