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 6355307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:44:19+00:00 2026-05-24T22:44:19+00:00

I have a model (call it Model_A) that I use to CRUD on a

  • 0

I have a model (call it Model_A) that I use to CRUD on a particular table defined by $name var. I also need to update another table (call it Model_B with different $name var) if the first operation in the other model is successful.

I’m trying to update table represented in Model_B from an action in class Model_A. I’m doing this by creating an instance of Model_B inside an action in Model_A. The update action fails fails because it seems to try to write to the table $name from Model_A, instead of the table $name from the instance of Model_B.

I suppose I could pass the result of the first update back to the controller and then go to the second model, but I’d rather do both updates at the same time.

Apart from an error in my coding, is there any obvious reason why my second update is not finding the right table.. and is this a reasonable aproach for what I’m wanting to do?

  • 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-05-24T22:44:19+00:00Added an answer on May 24, 2026 at 10:44 pm

    Most people think of a Model as coincident with a table class. In fact, they make models extend a base table class. For most simple CRUD type work, this is more or less fine. But as you get into more complex updates across multiple tables, or transaction scripts, you find awkward situations like the one you are asking about.

    In fact, a model is not a table. A model is an encapsulation of some logical part of your application’s business, not the implementation of storing it in a database.

    I worked on the code of Zend_Db_Table quite a bit a few years ago, and when I was writing the manual, I was careful not to refer to table classes as Models.

    So you may need to introduce a true Model class layer (which extends no base class), that knows how to do certain application-specific operations against one or more database tables, yet it is not your application’s Controller.

    Controller -> Model -> Table(s)
    

    This architecture is a great way to avoid repeating code if you have similar business tasks that are called from multiple controllers. It helps to decouple application functions and persistence details from your Controllers, which has benefits in code maintenance, testability, encapsulation, etc.

    Check out the free mini-book Domain-Driven Design Quickly (based on Eric Evans books), or the chapter "Magic Beans" in my book, SQL Antipatterns Volume 1: Avoiding the Pitfalls of Database Programming.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model that for edit/update actions only is logically split into two
In a webapp, i have a data-model (let's call it Item). The data of
I have model Article it has field title with some text that may contain
Lets say I have model inheritance set up in the way defined below. class
In my controller I have model operations that can return empty results. I've setup
I have a Model called Version that looks like this: from google.appengine.ext import db
I have a partial view that loops through its Model (a list of things)
Let's say I have a PHP Model-View-Controller framework that maps an address like http://example.com/admin/posts/edit/5
Let's say that you have a Model that looks kind of like this: public
Lets say I have three django model classes - lets call them A, B

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.