我有以下架构:
Text scoreText = new Text(scoreString);
scoreText.setFont(new Font("ARIAL", 30);
scoreText.setStyle("-fx-font-weight: bold;");
scoreText.setFill(Color.WHITE);
Pane scorePane = new Pane(scoreText);
scoreText.relocate(100, 100);
root.getChildren().add(scoreText);
我希望使用AciveRecord获取所有公开或私有的群组,而不是名为“MyAds”的特定广告组的一部分。我已经设法使用以下查询获取列表,但它看起来很难看,我确信有更好的方法来做到这一点。有人可以帮忙吗?
create_table "ad_groups", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "ad_placements", force: :cascade do |t|
t.integer "advertisement_id"
t.integer "ad_group_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["ad_group_id"], name: "index_ad_placements_on_ad_group_id", using: :btree
t.index ["advertisement_id"], name: "index_ad_placements_on_advertisement_id", using: :btree
end
create_table "advertisements", force: :cascade do |t|
t.string "name"
t.string "image"
t.string "link"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.date "expiry_date"
t.integer "company_id"
t.index ["company_id"], name: "index_advertisements_on_company_id", using: :btree
end
create_table "companies", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "groups", force: :cascade do |t|
t.string "name"
t.integer "company_id"
t.string "group_type"
t.datetime "created_at"
t.datetime "updated_at"
t.index ["company_id"], name: "index_groups_on_company_id", using: :btree
end
答案 0 :(得分:2)
OR
条件可以合并为一个IN
条件,如果您通过公共'和'私人'在数组中。您可能需要查看merge
以让Rails管理连接条件。这是一个可能的选择:
my_ad_groups = Group.joins(company: { advertisements: { ad_placements: :ad_group } }).merge(AdGroup.where(name: 'MyAds'))
Group.where(group_type: ['Public', 'Private']).where.not(id: my_ad_groups)