需要有关rails模型继承如何工作的更多信息

时间:2016-03-07 12:56:42

标签: ruby-on-rails

我有一个Ruby on Rails应用程序,我有一个名为“Fruits”的模型,其中包含一个底层数据库,  我这个DB我有像“Type”,“Value”和其他几列的列,在Type列下我有像“Apple”,“Orange”和“Mango”这样的数据。 我有其他模型,如“Apple”,“Orange”,“Mango”,所有这些模型都没有底层数据库,但继承了“Fruits”模型(我之前提到过的模型)。 在我编写Apple.find_by_Value(某个值)的代码中,这如何返回仅与Apple相关的数据?

1 个答案:

答案 0 :(得分:0)

您正在查看单表继承(STI)。它允许您为同一个表使用多个模型,使用final AtomicReference<ListenableFuture<ResponseEntity<String>>> future = new AtomicReference<>(asyncRestTemplate.getForEntity("http://localhost/foo", String.class)); final CountDownLatch latch = new CountDownLatch(1); future.addCallback(new ListenableFutureCallback<String>() { int retries; @Override public void onSuccess(String result) { if (notTheResultIWant) { future.set(asyncTemplate.getFor (...)); future.get().addCallback(this); retries++; } else { latch.countDown(); } } @Override public void onFailure(Throwable ex) { latch.countDown(); } }); if (latch.await(10, Timeunit.SECONDS) { ... future.get().get(); } 列存储每条记录的模型名称。

相关文档:http://api.rubyonrails.org/classes/ActiveRecord/Inheritance.html