Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»CodeSOD: Extended Models

    CodeSOD: Extended Models

    June 20, 2024

    If I’m being completely honest, I’m mildly anti-ORM. I’m not about to go on a rampage and suggest they should absolutely, never, ever, ever be used, but I think they tend to create a lot of problems. Instead of being a true mapping between our object model and our relational model, they’re their own tool, with its own idosynchracies, and a lot of “magic” that conceals its actual operation. For simple applications, they’re great, but once you start getting into something more complicated than basic CRUD operations, you’re in for a world of hurt. And that’s before someone makes a mistake with eager vs. lazy fetching.

    Today’s anonymous submission offers us a good example of another way the mismatch can go wrong between objects and relations.

    class Category_Product_Model extends Product_Model {
    protected $table_name = “categories_products”;
    }

    Product_Model is the model for our products in our ecommerce solution. Category_Product_Model is the join between products and categories. In no sane world would we consider Category_Product_Model a subclass of Product_Model- this implies that we can use a Category_Product in place of a Product. How much would you charge for a link between a product and it’s category? I happen to know that Legos belong in both the “toy” category and the “model building” category- what price would you put on that information? Who’s the vendor? (Me, I guess?) How many of those links do I have in inventory? Why… as many as you like. It’s just information.

    There are a few reasons this code might be like this. The most likely, I think, is that someone just didn’t care. It’s all models, pick one, inherit off it, and move on to the next. But there’s another reason, which would be so much worse.

    You see, they could have put functionality into Product_Model. It could be more than a simple model object, and have helper functions- helper functions which Category_Product_Model also wants to use. Instead of doing the right thing and refactoring that functionality out of the models, someone decided that inheritance was a convenient way to inject useful functionality into classes.

    Our anonymous submitter points out that this code had been in production for seven years by the time they found it, and this use of “creative subclassing” was rampant throughout their data model.

    [Advertisement]
    Otter – Provision your servers automatically without ever needing to log-in to a command prompt. Get started today!

    Source: Read More 

    Hostinger
    Facebook Twitter Reddit Email Copy Link
    Previous ArticleThe AI hype has made NVIDIA the world’s most valuable company, ahead of Microsoft and Apple — It’s the most profitable chip brand, too
    Next Article Gomphotherium – command line Mastodon client

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 17, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-40906 – MongoDB BSON Serialization BSON::XS Multiple Vulnerabilities

    May 17, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    This rugged power bank is one of the fastest I’ve used – and it’s so close to perfect

    Development

    CVE-2025-2517 – OpenText ArcSight Enterprise Security Manager Domain Reference Leak

    Common Vulnerabilities and Exposures (CVEs)

    Meet Android Agent Arena (A3): A Comprehensive and Autonomous Online Evaluation System for GUI Agents

    Development

    The rising price of Nintendo games makes supporting smaller titles and studios more important than ever — I’ll be voting with my wallet

    News & Updates
    GetResponse

    Highlights

    Device-Directed Speech Detection for Follow-up Conversations Using Large Language Models

    November 4, 2024

    This paper was accepted at the Adaptive Foundation Models (AFM) workshop at NeurIPS Workshop 2024.…

    Allen Institute for AI (Ai2) Launches OLMoTrace: Real-Time Tracing of LLM Outputs Back to Training Data

    April 11, 2025

    Palo Alto Networks Patches Critical Flaw in Expedition Migration Tool

    July 11, 2024

    WaveMaker releases AutoCode plugin for Figma for generating front-end components

    February 4, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.