tomjaguarpaw / haskell-opaleye

Other
602 stars 115 forks source link

Does the caveat about updateEasy and optional fields also apply to read only fields? #535

Closed ablygo closed 2 years ago

ablygo commented 2 years ago

So I was trying to update some rows in a database and kept getting a foreign key constraint violation, and changing the primary row from readOnly to optional and changing my update function from

update Row {..} = Row { primaryKey = () , ... }

to

update Row {..} = Row { primaryKey = Just primaryKey , ... }

fixed the issue. However, I ended up noticing a createdTime field that was also readOnly and didn't have a foreign key constraint was getting modified by the update, and found the discussion in #447. Given the behaviour I'm seeing, and the explanation there, I feel like it must also apply to readOnly fields, but neither the documentation for Update or readOnlyTableFields mention that.

I don't know if that's intended, or if I've somehow done something wrong, because the name readOnly seems extremely counterintuitive if it is (it would seem to imply there's no way to update the field without the field being modified). If it is then the documentation for Update and readOnlyTableFields should probably mention it.

tomjaguarpaw commented 2 years ago

Yes, thanks for prompting this. Indeed readOnly is completely broken for any writes. I should display a more prominent warning.

tomjaguarpaw commented 2 years ago

Thanks again for flagging this up. The next version I release will informally deprecated readOnlyTableField. It just shouldn't be used.