1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Commit graph

13 commits

Author SHA1 Message Date
ktmouk
5b4a516c1c Fixed odd behavior of inverse_of with multiple belongs_to to same class
Fix: #35204.

This PR added validation to `automatic_inverse_of` that foreign_keys are the same.

If class has multiple `belongs_to` to same class, `automatic_inverse_of` can find the wrong `inverse_name`.

```ruby
class Room < ActiveRecord::Base
  belongs_to :user
  belongs_to :owner, class_name: "User"
end

class User < ActiveRecord::Base
  has_one :room
  has_one :owned_room, class_name: "Room", foreign_key: "owner_id"
end

user = User.create!
owned_room = Room.create!(owner: user)

p user.room
```

The current `automatic_inverse_of` validates the `reflection` that found from associations.
However, its validation does not validate that foreign keys are the same.

so this issue can be fixed by adding a validation of foreign keys.

Co-authored-by: alpaca-tc <alpaca-tc@alpaca.tc>
Co-authored-by: cat2koban <taba.noritomo@moneyforward.co.jp>
Co-authored-by: luccafort <konishi.tatsuro@moneyforward.co.jp>
2020-11-21 02:06:21 +09:00
Bernardo Araujo
51443e22f3 Allow token length configuration for has_secure_token method
The minimum token length is set to 24 due to security constraints. We
can now specify a longer length through the length: parameter. This is
especially useful for cases when your data storage is case-insensitive
and you want to increase your entropy.
2019-04-09 17:25:50 -04:00
Kir Shatrov
831be98f9a Use frozen-string-literal in ActiveRecord 2017-07-19 22:27:07 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590, reversing
changes made to afb66a5a59.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Ryuta Kamizono
111ccc832b Chain scope constraints should respect own table alias
Fixes #27666.
2017-02-01 06:27:23 +09:00
Kir Shatrov
8312a0d222 Deprecate reflection class name to accept a class
The idea of `class_name` as an option of reflection is that passing a
string would allow us to lazy autoload the class.

Using `belongs_to :client, class_name: Customer` is eagerloading models more than necessary
and creating possible circular dependencies.
2017-01-09 13:08:33 -05:00
Xavier Noria
9617db2078 applies new string literal convention in activerecord/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:26:53 +02:00
Ryuta Kamizono
b7d229d1fa Correctly return associated_table when associated_with? is true
`AssociationQueryHandler` requires `association` initialized
`TableMetadata` even if `table_name == arel_table.name`.

Fixes #25689.
2016-07-10 11:42:51 +09:00
Kasper Timm Hansen
1aa1cec777 Revert "Merge pull request #20835 from glittershark/if-and-unless-in-secure-token"
This reverts commit 224eddfc0e, reversing
changes made to 9d681fc74c.

When merging the pull request, I misunderstood `has_secure_token` as declaring a model
has a token from birth and through the rest of its lifetime.

Therefore, supporting conditional creation doesn't make sense. You should never mark a
model as having a secure token if there's a time when it shouldn't have it on creation.
2016-01-14 21:52:03 +01:00
Griffin Smith
21c0a1f301 Support :if and :unless in has_secure_token
Pass through :if and :unless options from has_secure_token to the
generated before_create callback
2016-01-09 14:49:00 -05:00
Michael Ryan
b9a1e9a4b2 Add ActiveRecord::Base.suppress 2015-02-18 18:30:05 -05:00
robertomiranda
5a58ba3366 Add has_secure_token to Active Record
Update SecureToken Docs

Add Changelog entry for has_secure_token [ci skip]
2015-01-04 11:31:37 -05:00