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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:31:30+00:00 2026-05-24T13:31:30+00:00

I have two models Products and Offers. Products hasOne Offer. Models are binded with

  • 0

I have two models Products and Offers. Products hasOne Offer. Models are binded with

//Product model:
hasOne
  Offer
     foreignKey => false
     conditions => array(Product.productnumber = Offer.productnumber) // Just normal fields

//Offer model:
belongsTo
    Product

There can be many offers with same Offer.productnumber and different Offer.price. What I want to do is find all products so that there is only one offer present with cheapest Offer.price. But now when I trying to do that I get as many duplicate Products as there is Offers with same productnumber. How to avoid this?

I have also seen this: hasMany reduced to hasOne in CakePHP But no luck with containable.

Is only (easiest) option to get separate arrays and then combine them “manually”?

  • 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-24T13:31:31+00:00Added an answer on May 24, 2026 at 1:31 pm

    Product hasMany Offers. Product hasMany LowestOffer with an order clause in the relationship conditions array sorted on price ASC and a limit=>1 clause.

    Then do a find with containable and pull the LowestOffer back when you want just the single cheapest offer or pull back Offers when you want them all.

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

Sidebar

Related Questions

I have two models: class Product(models.Model): name = models.CharField(max_length=255) class ProductPhoto(models.Model): product = models.ForeignKey('Product',
I have two models, say Product and Bundle. products table is related to product_prices
In Django, I have two models: class Product(models.Model): name = models.CharField(max_length = 50) categories
I have two models: Price :belongs_to Products Product :has_many Prices I created new Prices
I have two models, Product and ProductImage, and I'd like to offer the possibility
As the title suggests I have two models Products And Orders which are actually
I have the following models: class Indicator(models.Model): name = models.CharField(max_length=200) category = models.ForeignKey(IndicatorCategory) weight
Let's say I have two models looking like this: class ProductType(models.Model): product_type = models.CharField(max_length=100)
Let's assume I have two Rails ActiveRecord models, CarType (make/model of car) and Car
I have two models, Product and Product_Methodology. In my product edit view I have

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.