My question is: for a given User, what SQL command could be used to select all associated initiators/initiatees for which the associated Relation is confirmed and of a given type?
The Ruby is as follows:
class User < AcitveRecord::Base
has_many :relations
end
class Relation < ActiveRecord::Base
belongs_to :initiator, class_name: "User"
belongs_to :initiatee, class_name: "User"
end
class CreateRelations < ActiveRecord::Migration
def change
create_table :relations do |t|
t.references :initiator
t.references :initiatee
t.boolean :is_confirmed, default: false
t.integer :type
end
end
end
Aucun commentaire:
Enregistrer un commentaire