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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:19:53+00:00 2026-06-09T11:19:53+00:00

My website/database is set up so that users habtm accounts, so that when a

  • 0

My website/database is set up so that users habtm accounts, so that when a person creates an account then a user the data is saved in the accounts_users table. A person logs in (using information from the users table) and create a template, the problem is the accounts_templates table is not pulling the accountid from the accounts_users table and it is throwing a database error.

the account hambt user,

user hambt account,

account hasmany templates,

templates belongto account

there is accounts_templates which contains id, account_id, template_id

there is accounts_users which contains id, account_id, user_id

there is templates which contains id, name, description, active

there is accounts which contains id, companyname, postcode, abn

there is users which contains id, username, password

template model

<?php
    class Template extends AppModel{ 
    var $name='Template'; 
    public $useTable = 'templates';
    public $primaryKey = 'id';

    public $belongsTo = array(
        'Account' => array(
            'classname' => 'Account',
            'foreignKey' =>'account_id'
            )
        );
    }

account template

var $hasMany = array(
        'Template' =>
            array(
                'className'=>'Template',
                'foreignKey'=>'account_id',
                )
            );

add function from the template controller

function add(){

    if($this->request->is('post')){

    $this->Template->create(); 

    if ($this->Template->save($this->request->data)) 
    { 
        $this->Session->setFlash('The template has been saved');
        $this->redirect( array('controller' => 'Fields','action' => 'add'));

    }
    else { $this->Session->setFlash('The template could not be saved. Please, try again.'); } 
    } 

  }
  • 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-06-09T11:19:54+00:00Added an answer on June 9, 2026 at 11:19 am

    In fact there is no what you called account_template model. One account has one template and then one template has many accounts.

    So, for this task you should have two models:
    Account and Template

    Account Model
    
    var $hasOne = array(
        'Template' =>
            array(
                'className'=>'Template',
    
                )
            );
    
    Template Model
    
    public $hasMany = array(
        'Account' => array(
            'classname' => 'Account',
            'foreignKey' =>'Template_id'
            )
        );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a website and a database of that website hosted locally on
I have a website that has one database I have also Desktop apps that
I have a mySQL database that tracks our projects and drives our website's display
Sorry for the newbie question! I'm making a small website that allows users to
I am working on a website which already has user access set up so
I'm currently trying to set up a website that uses both windows authentication and
I'm trying to insert data about a user on my website but I think
I have a database for a forum-like website. It has a 'users' table, which
I used the ASP.NET Configuration wizard to set up a web user. I then
My website has public-facing profiles. Users may have 145x145 profile images that are displayed

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.