1
0
mirror of https://github.com/jbranchaud/til synced 2026-07-07 09:30:34 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
nick-w-nick 466d1d969a Merge 295fe153ad into 43c6e08b34 2025-01-31 11:16:39 -05:00
jbranchaud 43c6e08b34 Add Add A Generated Column To A PostgreSQL Table as a Rails TIL 2025-01-30 23:10:23 -06:00
nick-w-nick 295fe153ad added mention of ES6 compatibility
Hello, I've added a small blockquote below the description to indicate that this method of accessing an indefinite number of function arguments has been superseded by the use of the spread operator via rest parameters for ES6+ compatibility.
2022-01-06 11:39:04 -05:00
3 changed files with 26 additions and 1 deletions
+2 -1
View File
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1579 TILs and counting..._ _1580 TILs and counting..._
See some of the other learning resources I work on: See some of the other learning resources I work on:
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators) - [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
@@ -946,6 +946,7 @@ See some of the other learning resources I work on:
- [Add A Check Constraint To A Table](rails/add-a-check-constraint-to-a-table.md) - [Add A Check Constraint To A Table](rails/add-a-check-constraint-to-a-table.md)
- [Add A Database Index If It Does Not Already Exist](rails/add-a-database-index-if-it-does-not-already-exist.md) - [Add A Database Index If It Does Not Already Exist](rails/add-a-database-index-if-it-does-not-already-exist.md)
- [Add A Foreign Key Reference To A Table](rails/add-a-foreign-key-reference-to-a-table.md) - [Add A Foreign Key Reference To A Table](rails/add-a-foreign-key-reference-to-a-table.md)
- [Add A Generated Column To A PostgreSQL Table](rails/add-a-generated-column-to-a-postgresql-table.md)
- [Add A Reference Column With An Index](rails/add-a-reference-column-with-an-index.md) - [Add A Reference Column With An Index](rails/add-a-reference-column-with-an-index.md)
- [Add ActiveRecord Error Not Tied To Any Attribute](rails/add-activerecord-error-not-tied-to-any-attribute.md) - [Add ActiveRecord Error Not Tied To Any Attribute](rails/add-activerecord-error-not-tied-to-any-attribute.md)
- [Add React With Webpacker To A New Rails App](rails/add-react-with-webpacker-to-a-new-rails-app.md) - [Add React With Webpacker To A New Rails App](rails/add-react-with-webpacker-to-a-new-rails-app.md)
@@ -5,6 +5,8 @@ an array-like object with all of the arguments to the function. Even if not
all of the arguments are referenced in the function signature, they can all of the arguments are referenced in the function signature, they can
still be accessed via the `arguments` object. still be accessed via the `arguments` object.
> For ES6+ compatibility, the `spread` operator used via [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) is preferred over the `arugments` object when accessing an abritrary number of function arguments.
```javascript ```javascript
function argTest(one) { function argTest(one) {
console.log(one); console.log(one);
@@ -0,0 +1,22 @@
# Add A Generated Column To A PostgreSQL Table
As of Rails 7, ActiveRecord supports generated columns for app's backed by a
PostgreSQL database. This is achieved with a `virtual` column.
```ruby
class CreateTags < ActiveRecord::Migration[8.0]
def change
create_table :tags, id: :bigint do |t|
t.string :value
t.virtual :normalized_value, type: :text, as: "lower(value)", stored: true
t.timestamps
end
end
end
```
With a table like this, any time we add a record with a `value`, PostgreSQL
computes and stores the `normalized_value` column based on that.
[source](https://blog.saeloun.com/2022/01/25/rails-7-postgres-support-for-generated-columns/)