Code Monkey home page Code Monkey logo

Comments (2)

cs91chris avatar cs91chris commented on May 20, 2024

Hi,
I do not well understand what output you expect.
The models have to extend the Model class of flask_autocrud (I don't know what your BaseModel is). Your models should look like this (I have not tested):

from flask_autocrud import Model

db = SQLAlchemy()


class Company(db.Model, Model):
    __tablename__ = 'company'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(150), nullable=False, unique=True)


class Address(db.Model, Model):
    __tablename__ = 'addresses'
    id = db.Column(db.Integer, primary_key=True)
    address_id = db.Column(db.Integer)
    company_id = db.Column(db.Integer, ForeignKey('company.id'))
    company = relationship(Company, backref="addresses")

You can see an example, where entities are artists and albums, here

def test_related(client):

Actually is not possible, with GET method, to fetch multiple related resources and applying filters on it.

Let me know

from flask_autocrud.

cs91chris avatar cs91chris commented on May 20, 2024

Hi @maikotz there is new release available. Now even multiple related resource are retrived with GET.
The following is an example that should fit your need:

curl -XGET 'http://127.0.0.1:5000/artist?_related=Album&_fields=Name&_no_links='

{
    "ArtistList": [
        {
            "AlbumList": [
                {
                    "AlbumId": 4
                },
                {
                    "AlbumId": 348
                },
                {
                    "AlbumId": 349
                }
            ],
            "ArtistId": 1,
            "Name": "AC/DC"
        },
        {
            "AlbumList": [
                {
                    "AlbumId": 3
                }
            ],
            "ArtistId": 2,
            "Name": "Accept"
        }
    ]
}

from flask_autocrud.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.