• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating Groups: table and model

[quote author="Nouman6" date="1267583313"]
hmm I was under the impression that checking for a unique entry such as the name was done by the controller during form_validation through callback. Here's how I have it setup.

You're right - that will work well here, by the looks of your code. I just usually get worried about transactional integrity, but it's a pretty straightforward sequence at the moment.

Depending how large your member_model and group_model are going to be, and how keen you are on separating them, and how much interplay exist between the various methods within each .. you could combine them.

Keeping them separate requires managing inter-model communication (a common cause of confusion around here). Previous straw polls suggested files around 500 lines or so were 'about right', but obviously it's hugely dependent on traffic, design preferences, performance expectations, code complexity and so on.

The approach you've described looks like a good hybrid - having the group_model own a couple of tables.

Personally I find the _model suffix on Model names to be cumbersome, so I come up with names that describe the aggregated functionality, or just use near-synonyms. (My Member model manages the dozen or so tables that things like my People controller rely on, f.e.)

haha ya I have my _models and my _views suffixes, but I understand what yo umean. Just to keep me a little less confused for the time being Smile

Well I've reworked it a bit from your help to now be:

            if($query = $this->group_model->create_group($groupname)){ //pass model
            }else{ // passed form, failed model
where I'm taking the groupname into a variable and then passing it to the model instead of retrieving post entries from the model:

and this in the model:

function create_group ( $groupname = NULL )  {
        $this->db->insert('group', $groupname);
        $group_user_id = $this->db->insert_id();//id of the new group
        $group_user_data = array(
            'group_id' => $group_user_id,
            'user_id' => $this->session->userdata('user_id')
        $this->db->insert('group_user', $group_user_data);
        return true;

and I'm not sure if it's the perfect way, it is working so if there is a better MVC pattern, again, I'd love to know Smile

Now I'm also at my first area to finally retrieve data using this database design, and I'm a bit lost

for example at the dashboard, the user will now see a list of Groups they are apart of (list of the group name's) now I know how to do this with a single table, but now I have to basically: use user_id from session => get list of rows with that user_id from group_user, THEN use the group_id's from these rows to retrieve a list of group names from the group table.

but I have no idea how to get started on the controller x]

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.