NoBrainerORM / nobrainer

Ruby ORM for RethinkDB
http://nobrainer.io/
Other
386 stars 49 forks source link

Join with conditions #245

Closed ghost closed 3 years ago

ghost commented 7 years ago

Good day. Help please find me a solution because in the documentation I can not find a similar case.

I have two related tables (table_one has many table_two table_two has table_one_id field). I need to make a query from two tables with the following condition: where table_one.updated_at < table_two.logged_at.

Thank you in advance for your help.

nviennot commented 7 years ago

Can you clarify your question please? Snippet of code would be helpful

ghost commented 7 years ago
class FirstTable

  include NoBrainer::Document
  include NoBrainer::Document::Timestamps

  has_many :second_tables

  field :field1,          type: DateTime
end

class SecondTable

  include NoBrainer::Document
  include NoBrainer::Document::Timestamps

  belongs_to :first_table

  field :field2,          type: DateTime
end

I need join query like:

FirstTable.join(:second_tables).where("first_table.field1 <  second_table.field2")
ghost commented 7 years ago

@nviennot Do you have any ideas on this matter?

nviennot commented 7 years ago

I'm not sure, you probably want to write custom RQL

zedtux commented 3 years ago

I'm closing this issue due to its age but feel free to update it if needed.