Score:0

Adding conditional comparison of two columns in relationship

ma flag

I am trying to put value comparision while creating relationship. When i give direct value that works perfectly fine. but i wanted to pass column name with alias to get required results.

This is working fine

$this->query->add_where(
        $this->options['group'],
        db_and()
          ->condition("class.end_time", 1625047346 , '<=')
    );

output
WHERE ((( (class.end_time <= 1625047346) ))AND ...............

This is not working. it takes alias.column as value

$this->query->add_where(
        $this->options['group'],
        db_and()
          ->condition("class.end_time", "class1.end_time" , '<=')
    );

output
WHERE ((( (class.end_time <= 'class.end_time') ))AND ...............

Score:0
ma flag

I found a solution. I just passed all the conditions as an extra text after join and it works.

This is how I passed text while joining two tables. You can pass extra while constructing join as a fifth parameter.

class mymodule_booking_classes_relationship  extends views_handler_relationship {

    function query() {
    
        $extra = "class.end_time <=  class1.start_time  ";
        $extra .= " or class.start_time >= class1.end_time ";

        $join3 = new views_join;
        $join3->construct('class_table', 'node', 'nid', 'course_id', $extra, 'INNER'); 
        $this->alias = $this->query->add_relationship('class1', $join3, 'class1');

    }
}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.