PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 8, 2022

[FIXED] Does associative table need model in Yii framework?

 March 08, 2022     many-to-many, model, php, yii     No comments   

Issue

I have many to many relationship and in the MYSQL database I have an associative table for them, now do I need a model for that table or it's just enough to declare it in the relation() function

public function relations()
{
return array(
'store'=>array(self::MANY_MANY, 'store',
                   'medinventory(MedID_FK, StoreID_FK)'));
}

Solution

You don't need a model for the intermediate table if you are only using it for the mapping.

You would need a model in case this table holds other attributes that need to be accessed.

for example considering your many to many relationship between store and inventory.

If you need to add an attribute to the medinventory table, to tell the application when was the relation created (created_time), and later on you need to access that property, then yes, would need to create a model.



Answered By - Asgaroth
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing