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

  • Home
  • SEARCH
  • 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 7511329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:30:59+00:00 2026-05-29T23:30:59+00:00

Ok so i have two models: 1: pv_array (photovoltaic array) 2: module (photovoltaic module)

  • 0

Ok so i have two models:

1: pv_array (photovoltaic array)
2: module (photovoltaic module)

there is a MANY_MANY relation between both of them:

        return array(           
                'modules' => array(self::MANY_MANY, 'module', 'module_to_array(array_id, module_id)'),
        );

        return array(
                'arrays' => array(self::MANY_MANY, 'pv_array', 'module_to_array(module_id, array_id)'),
        );

The problem is when i add modules to an array i need the ability to add multiple instances of the same module to an array… i can do this no problem, when i check the Database table module_to_array there are multiple entries present.

Although when i now go to access the modules in the array as follows:

$pv_array = pv_array::model()->findByPk( 2 );
echo count( $pv_array->modules);

it only counts single instances of modules and not the multiple instances of modules as are present…??

for example if i added 3 x ModuleXYZ and 2x ModuleABC to Array1 i would only get the following

echo count( $Array1->modules ); // would echo 2

where i would want it to echo 5

any idea?

  • 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-29T23:31:00+00:00Added an answer on May 29, 2026 at 11:31 pm

    ok i discovered the best solution to this problem after about 4 hours of wading through code… just to do the relation manually with a magic method

    1. first comment out the relation

    2. create a magic property the same as the relation propery e.g

          var $_modules = array();
      
    3. use the magic get method and dbcriteria to build the query manually

      public function getModules() 
      {
           $criteria = new CDbCriteria;
           $criteria->join = 'LEFT JOIN component_to_array ON component_to_array.array_id = '.$this->id.' AND t.id = component_to_array.component_id';
           $criteria->condition = 'component_to_array.array_id = '.$this->id.'';
      
           return component::model()->findAll($criteria);
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models, Article and Post that both inherit from a base model
I have two models. We'll call them object A and object B. Their design
I have two models: Person and Relation. The second one stores information about relations
I have two models Customer and Referal. Both have an email attribute. Referal belongs
I have two models in relation one-to-many: class Question(db.Model): questionText = db.StringProperty(multiline=False) class Answer(db.Model):
I have two models in Django linked together by ManyToMany relation like this: class
I have two models indexed for searching (User and Item). I'm trying to do
I have two models, Room and Image . Image is a generic model that
I have two models: Show and Venue . Show has one venue while each
I have two models in my Django application, for the purposes of storing search

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.