is there any specific reason why there is no strategy specified for on_delete on resource owner foreign keys for oauth_access_tokens and oauth_access_grants tables?
I see that the example in documentation recommends to specify :delete_all for dependant option:
https://github.com/doorkeeper-gem/doorkeeper-provider-app/blob/master/app/models/user.rb#L16
but, the database migration, does not specify any at database level:
https://github.com/doorkeeper-gem/doorkeeper/blob/1cd750b2bfc68b641c11a8ec0297feb3825eb97b/spec/dummy/db/migrate/20151223192035_create_doorkeeper_tables.rb#L66
Below is an example of code showing the issue:
class User < ActiveRecord::Base
#...
has_many :access_grants,
class_name: 'Doorkeeper::AccessGrant',
foreign_key: :resource_owner_id,
dependent: :delete_all # or :destroy if you need callbacks
has_many :access_tokens,
class_name: 'Doorkeeper::AccessToken',
foreign_key: :resource_owner_id,
dependent: :delete_all # or :destroy if you need callbacks
#...
end
user = User.create
application = Doorkeeper::Application.create(name: 'test')
Doorkeeper::AccessToken.create_for(application: application, resource_owner: user, scopes: '')
user.delete # => ActiveRecord::InvalidForeignKey
user.destroy # => true
I would expect destroy and delete both work.
Thank you!
Dani Popa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.