2014-12-29 113 views
1

如何查询淘汰时间表谁拥有具有空appointment_id slot_details。下面是一个示例数据集:用途,其中查询在JSONB数据类型在Rails的Postgres的

id: 98, 
    consulting_location_doctor_id: 498, 
    schedule_date: Thu, 15 Jan 2015 00:00:00 IST +05:30, 
    slot_details: 
    [{"end"=>"2015-01-15T15:00:00.000+00:00", "start"=>"2015-01-15T14:30:00.000+00:00", "title"=>" 2:30 pm to 3:00 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T15:30:00.000+00:00", "start"=>"2015-01-15T15:00:00.000+00:00", "title"=>" 3:00 pm to 3:30 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T16:00:00.000+00:00", "start"=>"2015-01-15T15:30:00.000+00:00", "title"=>" 3:30 pm to 4:00 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T16:30:00.000+00:00", "start"=>"2015-01-15T16:00:00.000+00:00", "title"=>" 4:00 pm to 4:30 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T17:00:00.000+00:00", "start"=>"2015-01-15T16:30:00.000+00:00", "title"=>" 4:30 pm to 5:00 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T17:30:00.000+00:00", "start"=>"2015-01-15T17:00:00.000+00:00", "title"=>" 5:00 pm to 5:30 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T18:00:00.000+00:00", "start"=>"2015-01-15T17:30:00.000+00:00", "title"=>" 5:30 pm to 6:00 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T18:30:00.000+00:00", "start"=>"2015-01-15T18:00:00.000+00:00", "title"=>" 6:00 pm to 6:30 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T19:00:00.000+00:00", "start"=>"2015-01-15T18:30:00.000+00:00", "title"=>" 6:30 pm to 7:00 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T19:30:00.000+00:00", "start"=>"2015-01-15T19:00:00.000+00:00", "title"=>" 7:00 pm to 7:30 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T20:00:00.000+00:00", "start"=>"2015-01-15T19:30:00.000+00:00", "title"=>" 7:30 pm to 8:00 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T20:30:00.000+00:00", "start"=>"2015-01-15T20:00:00.000+00:00", "title"=>" 8:00 pm to 8:30 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T21:00:00.000+00:00", "start"=>"2015-01-15T20:30:00.000+00:00", "title"=>" 8:30 pm to 9:00 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T21:30:00.000+00:00", "start"=>"2015-01-15T21:00:00.000+00:00", "title"=>" 9:00 pm to 9:30 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T22:00:00.000+00:00", "start"=>"2015-01-15T21:30:00.000+00:00", "title"=>" 9:30 pm to 10:00 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T22:30:00.000+00:00", "start"=>"2015-01-15T22:00:00.000+00:00", "title"=>"10:00 pm to 10:30 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T23:00:00.000+00:00", "start"=>"2015-01-15T22:30:00.000+00:00", "title"=>"10:30 pm to 11:00 pm", appointment_id: ""}, 
    {"end"=>"2015-01-15T23:30:00.000+00:00", "start"=>"2015-01-15T23:00:00.000+00:00", "title"=>"11:00 pm to 11:30 pm", appointment_id: ""}, 
    {"end"=>"2015-01-16T00:00:00.000+00:00", "start"=>"2015-01-15T23:30:00.000+00:00", "title"=>"11:30 pm to 12:00 am", appointment_id: ""}], 
    start_and_end_time: Thu, 15 Jan 2015...Fri, 16 Jan 2015, 
    deleted_at: nil, 
    deleted_by_id: nil, 
    created_at: Tue, 30 Dec 2014 04:28:06 IST +05:30, 
    updated_at: Tue, 30 Dec 2014 04:28:06 IST +05:30> 

我也尝试了guides中的示例。没有关于在json数组上查询的例子。请帮忙。

+0

可能重复[如何使Rails 4.2与Postgres Jsonb一起工作?](http://stackoverflow.com/questions/27462929/how-to-make-rails-4-2-work-with-postgres-jsonb) – khampson

+0

任何特定的原因你为此使用JSON?你的'slot_details'看起来是非常一致的结构,一个单独的表可能是一个更好的主意。 –

+0

@ muistooshort我决定去这个结构,因为。你看到的那一行是为了一个单一的医生咨询位置。医生可以有许多这样的咨询位置,每个咨询位置在一天中有多个位置。如果我把它作为一个独立的桌子出来,不会很快变得太大? – Aravind

回答

0

也许这可以帮助你:

slot -> 'slot_details' @> '[{"end"=>"2015-01-15T20:00:00.000+00:00"}]' 

的想法是问,如果部分子阵列包含。如果你在一个阵列中BUN的对象不是会改为(让我们说我们有一个配置文件对象):

profile -> 'basics' @> '{"name":"john"}' 

不要上当,想在这里使用?代替@>

相关问题