topaz v0.0.5 Release Notes

Release Date: 2016-12-07 // over 7 years ago
  • Converting models to jsons is a necessary feature for who develops api server.
    Now your api easily generate and return jsons of models with Topaz.

    For example, when we have

    JsonParent(name)
     - JsonChild(age, p_id)
       - JsonToy(name, price, c_id)
        - JsonPart(t_id)
     - JsonPet(p_id)
    

    Then we can write like

    p = JsonParent.select.firstputs p.jsonputs p.json({include: :childlen, except: :id})puts p.json({include: {childlen: {except: [:id, :p\_id]}, pets: nil} })puts p.json({include: {childlen: {include: {toies: {include: :parts, only: :price} } }, pets: nil} })
    

    We got

    {"id": 1, "name": "John"}
    
    {"name": "John", "childlen": [{"id": 1, "age": 12, "p_id": 1}, {"id": 2, "age": 15, "p_id": 1}, {"id": 3, "age": 23, "p_id": 1}]}
    
    {"id": 1, "name": "John", "childlen": [{"age": 12}, {"age": 15}, {"age": 23}], "pets": [{"id": 1, "p_id": 1}, {"id": 2, "p_id": 1}, {"id": 3, "p_id": 1}, {"id": 4, "p_id": 1}]}
    
    {"id": 1, "name": "John", "childlen": [{"id": 1, "age": 12, "p_id": 1, "toies": [{"price": 10, "parts": [{"id": 1, "t_id": 1}]}, {"price": 12, "parts": []}]}, {"id": 2, "age": 15, "p_id": 1, "toies": [{"price": 15, "parts": [{"id": 2, "t_id": 3}, {"id": 3, "t_id": 3}, {"id": 4, "t_id": 3}]}]}, {"id": 3, "age": 23, "p_id": 1, "toies": []}], "pets": [{"id": 1, "p_id": 1}, {"id": 2, "p_id": 1}, {"id": 3, "p_id": 1}, {"id": 4, "p_id": 1}]}