Flask restless - search filter for .property! = Val relationship in case of one-to-many relationship

Sqlalchemy flag models for book and action tables :

class Book(db.Model):

    __tablename__ = 'book'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(255))
    activity = db.relationship('Actions')

class Actions(db.Model):

    __tablename__ = 'actions'

    id = db.Column(db.Integer, primary_key=True)
    book_id = db.Column(db.Integer, db.ForeignKey('book.id'), nullable=False)
    action = db.Column(db.Enum(['requested', 'issued', 'opened', 'closed']), nullable=True)
    created_on = db.Column(db.DateTime, default=_get_date_time)

This is mainly a one-to-many relationship between book and action. And I use flask-restless for the API.

I need to get

All books that were not closed

I tried below search queries

q={
"filters": [
    {
      "name": "activity",
      "op": "any",
      "val": {
        "name": "action",
        "op": "not_equal_to",
        "val": "closed"
      }
    }
  ]
}

and

q={
  "filters": [
    {
      "name": "activity",
      "op": "any",
      "val": {
        "name": "action",
        "op": "not_in",
        "val": ["closed"]
      }
    }
  ]
}

But I get the wrong result

{
"num_results": 30,
"objects": [
{
  "activity": [
    {
      "action": "opened",
      "created_on": "2015-06-05T17:05:07",
      "id": 31
    },
    {
      "action": "closed",
      "created_on": "2015-06-05T17:05:44",
      "id": 32
    }
  ],
  "id": 1,
  "name": "K&R"
  ....
},
...
]
"page": 1,
"total_pages": 3
}

Am I making some mistake here, or is this kind of thing impossible to worry about?

Please help me.

+4
source share
1 answer

Try the following:

q = { "filters":[   
         {
          "name":"activity__action", 
          "op":"not_equal_to", 
          "val":"closed"
         }
      ]
}
+1
source

All Articles