Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8909403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:25:21+00:00 2026-06-15T03:25:21+00:00

The model is like this(in SQLAlchemy): Class Cell(Base): __tablename__ = cell id = Column(Integer)

  • 0

The model is like this(in SQLAlchemy):

Class Cell(Base):
    __tablename__ = "cell"
    id = Column(Integer)
    name = Column(String)

Class Sample(Base):
    __tablename__ =  "cell"
    id = Column(Integer)
    factor_id = Column(Integer, ForeignKey("cell.id"))
    cell = relationship(Cell, backref = 'sample', order_by = "Cell.id")

When I execute the query like this:

DBSession.query(Sample).filter(Sample.cell.name == "a_string")

It throws an exception like this:

File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/attributes.py", line 139, in __getattr__
key)
AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object has an attribute  'name'

It seems that the cell field in Sample class doesn’t have a field called name. Then how can I query Cell.name in Sample class with cell field? Does anyone have ideas about this?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:25:22+00:00Added an answer on June 15, 2026 at 3:25 am

    There are various ways to achieve that:

    1. use join(…) – I would opt for this one in your case

    qry = session.query(Sample).join(Cell).filter(Cell.name == "a_string")
    
    >> SELECT sample.id AS sample_id, sample.factor_id AS sample_factor_id
    >> FROM sample JOIN cell ON cell.id = sample.factor_id
    >> WHERE cell.name = :name_1
    

    2. use any/has(…) – this will use a sub-query

    qry = session.query(Sample).filter(Sample.cell.has(Cell.name == "a_string"))
    
    >> SELECT sample.id AS sample_id, sample.factor_id AS sample_factor_id
    >> FROM sample
    >> WHERE EXISTS (SELECT 1
    >> FROM cell
    >> WHERE cell.id = sample.factor_id AND cell.name = :name_1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a sqlalchemy model that is set up like this: class Entry(Base): __tablename__
I have a SQLAlchemy model like this: class Group(Base): __tablename__ = 'groups' id =
I have a simple model like this: class User < ActiveRecord::Base serialize :preferences end
I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have model class CreatedMixin(object): __abstract__ = True @declared_attr def created_by(cls): return Column(Integer, ForeignKey('user.user_id',
Let's consider the following table models for sqlalchemy in python. class Worker(Base): id Column(Integer,
I have a simple model like this: class Auction(models.Model): name = models.CharField() class Item(models.Model):
How close can I get to defining a model in SQLAlchemy like: class Person(Base):
I have a model like this: class Transaction < ActiveRecord::Base def amount self[:amount].abs end
I have a model like this: class Group(db.Model): name = db.StringProperty() description = db.TextProperty()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.