Welcome Guest, Not a member yet? Register   Sign In
question about writing model
#1

[eluser]dexcell[/eluser]
hello, i would like to ask if my approach of writing is correct.

i have 2 models, let's name it entries_model and groups_model

entries_model do the low handling to entries table.
groups_model do the low handling to group table.

then in one of functions of entries model, it needs to connect to group table to check something,

the question:
should i write (connecting to group table manually) in one of entries_model function? or should i just load group_model and call the method?

for illustration (if i load the group_model, it works tough i don't know if it's correct way since i'm new to CI):

Code:
class Entries_model extends Model
{
  function Entries_model()
  {
    parent::Model();
    
    $this->load->model('groups_model');
  }

  function checkSomething()
  {
    $this->groups_model->checkSomething(1);
  }
}
#2

[eluser]lmv4321[/eluser]
Is there a reason that you are using separate databases instead of separate tables in the same database?
#3

[eluser]dexcell[/eluser]
[quote author="lmv4321" date="1224732312"]Is there a reason that you are using separate databases instead of separate tables in the same database?[/quote]

whoops sorry, i mean table. updated the post. *maybe it was midnight when i wrote that, you know :roll: *
#4

[eluser]Colin Williams[/eluser]
I think it's okay for models to make use of other models in some instances, but I see no problem with, say, the Entry model doing some queries that JOIN the groups tables. I'd keep most write/update stuff separate if possible and if it doesn't hinder performance (amount of queries) too much.
#5

[eluser]dexcell[/eluser]
thanks




Theme © iAndrew 2016 - Forum software by © MyBB