You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i've already submitted pullrequest #171 for this problem, but got no response. since i had some time to look into this issue a bit more, i thought i'd open a issue as it a more appropriate place for discussion.
so, the problem is that recursively restoring a has_one relationship will create a wrong sql query, which in postgres will lead to PG::DatatypeMismatch: ERROR: argument of AND must be type boolean, not type integer ( and subsequently ActiveRecord::StatementInvalid) . when using sqlite, the query is still wrong but does not break.
the query built is (sqlite):
SELECT "paranoid_model_with_belongs".* FROM "paranoid_model_with_belongs"
WHERE ("paranoid_model_with_belongs"."deleted_at" IS NOT NULL)
AND (paranoid_model_with_has_one_id)
ORDER BY "paranoid_model_with_belongs"."id" ASC LIMIT 1
due to AND (paranoid_model_with_has_one_id) instead of AND "paranoid_model_with_belongs"."paranoid_model_with_has_one_id" = 1, in restore_associated_records(), the correct record to be restored is never selected. this might be what's happening in #163.
.where(association_foreign_key, self.id) should be .where(association_foreign_key => self.id). this leads to the desired query
SELECT "paranoid_model_with_belongs".* FROM "paranoid_model_with_belongs"
WHERE ("paranoid_model_with_belongs"."deleted_at" IS NOT NULL)
AND "paranoid_model_with_belongs"."paranoid_model_with_has_one_id" = 1
ORDER BY "paranoid_model_with_belongs"."id" ASC LIMIT 1
so, if you think my pullrequest is missing anything or if i'm missing something on the whole situation just say so, i'd be happy to comply.
cheers
The text was updated successfully, but these errors were encountered:
hi!
i've already submitted pullrequest #171 for this problem, but got no response. since i had some time to look into this issue a bit more, i thought i'd open a issue as it a more appropriate place for discussion.
so, the problem is that recursively restoring a has_one relationship will create a wrong sql query, which in postgres will lead to
PG::DatatypeMismatch: ERROR: argument of AND must be type boolean, not type integer
( and subsequentlyActiveRecord::StatementInvalid
) . when using sqlite, the query is still wrong but does not break.the query built is (sqlite):
due to
AND (paranoid_model_with_has_one_id)
instead ofAND "paranoid_model_with_belongs"."paranoid_model_with_has_one_id" = 1
, inrestore_associated_records()
, the correct record to be restored is never selected. this might be what's happening in #163..where(association_foreign_key, self.id)
should be.where(association_foreign_key => self.id)
. this leads to the desired queryso, if you think my pullrequest is missing anything or if i'm missing something on the whole situation just say so, i'd be happy to comply.
cheers
The text was updated successfully, but these errors were encountered: