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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:42:33+00:00 2026-05-26T14:42:33+00:00

Hello Everything is right? My problem is the following: I have 3 tables: create

  • 0

Hello Everything is right?
My problem is the following:

I have 3 tables:

create table products (
    id int not null auto_increment primary key,
    name varchar(80) not null,
    mold varchar(80),
    amount int,
    value decimal(10,2),
    real_value decimal(10,2),
    created datetime,
    modified datetime,
    active boolean default 1
);

create table sales (
    id int not null auto_increment primary key,
    customer_id int not null,
    method_payment_id int not null,
    portions smallint(4),
    entry decimal(10,2),
    subtotal decimal(10,2),
    total decimal(10,2),
    debtor decimal(10,2), 
    expiration_date datetime,
    created datetime,
    modified datetime,
    active boolean default 1
);

create table products_sales (
    product_id int not null,
    sale_id int not null,
    amount smallint(4),
    value decimal(10,2)
);

In products_sales (HABTM) I had to add two extra fields (amount and value), because the value of a product is unstable and the other is the quantity purchased by the customer.

When I put in add() page:

  echo $this->form->input('Product');

CakePHP renders a , until then I understand.

But my need is: the customer must choose the product and the amount of it, or even if it is, the product value is also sent, not only the id (anything, I create a page just to report the amount, after confirmation ‘the sale’).

Then:
1 – How do I save the ID and value of the product at the same time?
2 – I am using the tables / relationships the right way?
3 – what better way to do this?

Sorry for my English.
I hope you understand.

  • 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-26T14:42:33+00:00Added an answer on May 26, 2026 at 2:42 pm

    Rather than HABTM, I think you want to use “hasMany through”, where you create a separate model for products_sales. Here’s a description from the Cake manual:

    http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#hasmany-through-the-join-model

    There’s a more complete description in the Cake 1.3 manual:

    http://book.cakephp.org/view/1650/hasMany-through-The-Join-Model

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have both Rails2 and Rails3(beta 3) installed by Ruby Gems. Everything right
So hello everyone I have a big problem right now with a button that
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
hello i have a problem that's maybe difficult to descripe, i have an application,
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Hello we have an SQL server application running over a low bandwith connection. We
I'm following this iPhone tutorial from Apple and I think I did everything correctly,
I have a problem with size calculation in Qt when adding new widgets at
Hello I have been tasked with creating a fairly complex web application in php,
Hello to all you people out there I have been trying to download the

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.