3 ms·
As someone who doesn't know Rails, the following code seems odd to me: class Team < ApplicationRecord has_many :players, dependent: :destroy_async end
by tiffanyh 2y ago
As someone who doesn't know Rails, the following code seems odd to me:
class Team < ApplicationRecord
has_many :players, dependent: :destroy_async
end
Specifically the following part:
dependent: :destroy_async
- chris12321 2y agoRuby methods can have both positional and keyword arguments, so, in this case, the `has_many` method takes the symbol `:players` as an argument and takes a keyword argument called `dependent:` which is being passed the symbol `:destroy_async`. Where a symbol in Ruby is an immutable identifier. So a method like this would be defined as something like: def has_many(model_name, dependent:) puts model_name.to_s puts dependent.to_s end Which you could then call as: has_many(:players, dependent: :destroy_async) or has_many :players, dependent: :destroy_async Since you don't need to put parenthesis around method arguments in ruby.