This project is archived and is in readonly mode.
"Returning ID" does not work due to trigger
-
Kane
i dont get it. why dont you just change your trigger to return the id?
also i dont quite get the last part
However, I suggest that Rails should never return a nil value after a successful save statement. There should be kind of check for the value of id before assigning it back to the ActiveRecord instance.
Does person.save return true?
you think it should return false and probably abort the transaction cause no id is given? -
Nghi Pham
i dont get it. why dont you just change your trigger to return the id? Yes, "return true" in the trigger may somehow solve the problem. However, what I mean here is the stability of Rails: it should always retrieve the proper id after an insert regardless of whether or not "insert into...returning id" query is supported properly.
In this case, it's a fault of PostgreSQL itself that a trigger with "return null" breaks the "returning id" query (null returned). So, I suggest that Rails should not rely on this unstable feature of PostgreSQL. It should do extra work to make sure "returning id" is returning the right id; otherwise, try other way to obtain the newly inserted id
Does person.save return true? you think it should return false and probably abort the transaction cause no id is given? Yes, I think it should, in the worst case!
However, as I mentioned above, this is a problem of PostgreSQL and Rails should have a workarround for this -
Nghi Pham
i dont get it. why dont you just change your trigger to return the id?
Yes, "return true" in the trigger may somehow solve the problem. However, what I mean here is the stability of Rails: it should always retrieve the proper id after an insert regardless of whether or not "insert into...returning id" query is supported properly.
In this case, it's a fault of PostgreSQL itself that a trigger with "return null" breaks the "returning id" query (null returned). So, I suggest that Rails should not rely on this unstable feature of PostgreSQL. It should do extra work to make sure "returning id" is returning the right id; otherwise, try other way to obtain the newly inserted id
Does person.save return true? you think it should return false and probably abort the transaction cause no id is given?
Yes, I think it should, in the worst case!
However, as I mentioned above, this is a problem of PostgreSQL and Rails should have a workarround for this