MyModel.select('a, b, c').all
This returns the following from a database:
+---+---+---+
| a | b | c |
+---+---+---+
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | 9 |
+---+---+---+
Question: How would I include a fourth column with the result of an SQL function?
i.e.
+---+---+---+---------------------+
| a | b | c | MYFUNCTION(a, b, c) |
+---+---+---+---------------------+
| 1 | 2 | 3 | 123 |
| 4 | 5 | 6 | 456 |
| 7 | 8 | 9 | 789 |
+---+---+---+---------------------+
The following didn't work:
MyModel.select('a, b, c, MYFUNCTION(a, b, c)').all
although, if I use AS to give the column the name of a valid model attribute, it works:
MyModel.select('a, b, MYFUNCTION(a, b, b) AS c').all
+---+---+-----+
| a | b | c |
+---+---+-----+
| 1 | 2 | 122 |
| 4 | 5 | 455 |
| 7 | 8 | 788 |
+---+---+-----+
I would prefer to solve this within the context of the model rather than reverting to raw SQL as I also need to utilise scopes.
Any suggestions much appreciated.