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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:23:40+00:00 2026-05-30T05:23:40+00:00

I am currently trying to manipulate a database with way too many relations. i

  • 0

I am currently trying to manipulate a database with way too many
relations. i wont make it complex for you, so here is a very
simplified example:

my table (animals):
id, type, title

  • 1, big, elephant
  • 2, big, giraffe
  • 3, small, cat
  • 4, small, dog

what i want to do is to have two models “Big” and “Small”.
“Big” model will only take care of animals with type ‘big’ (elephant
and giraffe),
and “Small” model will take care of animals with type ‘small’ (cat and
dog).

is it possible 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-30T05:23:42+00:00Added an answer on May 30, 2026 at 5:23 am

    Yes, you can create the model called BigAnimal and then define the $useTable = ‘animals’; Then define the beforeFind and the beforeSave to set the type to ‘big’ every time. Then you can do the same for the SmallAnimal model. Here is an example

    class BigAnimal extends AppModel {
       var $useTable = 'animals'; 
    
       function beforeFind($queryData) {
            // set type to big here
       }
    
       function beforeSave() {
           // set type to big here
       }
    }
    

    While this is the way you can accomplish this, it seems it would be better to keep 1 to 1 model to table. Then you could add the necessary functions to query big and little animals all from the same model. It keeps the code a little cleaner. So something like:

    class Animal extends AppModel {
    
       function findBigAnimals() {
           return $this->find('all', array('conditions' => array('type' => 'big')));
       }
    
       function findSmallAnimals() {
           return $this->find('all', array('conditions' => array('type' => 'small')));
       }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to manipulate a unordered list with jQuery, essentially I have
I'm currently trying to read in an XML file, make some minor changes (alter
Here's the deal. I have a large character array and am trying to manipulate
I'm currently hacking away, trying to replicate Coda's tooltip: http://jqueryfordesigners.com/coda-popup-bubbles/ Check out my example
I am currently trying to manipulate the contents of two different types of controls
I currently trying to find a solution, how to ensure that a test fails
I'm currently trying out db4o (the java version) and I pretty much like what
I'm currently trying to build a personal website to create a presence on the
I'm currently trying to port a SIP stack library (pjSIP) to the PSP Console
I'm currently trying to get into the Java EE development with the Spring framework.

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.