Skip to content

> This is confusing behavior for a function, but to change it would lead to breaking changes on users of this base library. #45

@ipundit

Description

@ipundit
          > This is confusing behavior for a function, but to change it would lead to breaking changes on users of this base library.

Well, we're gearing up to do the first major version release in more than a decade, here, so if you want to break stuff now is the time to do it. For what it's worth there are a few other API-breaking changes that I felt were necessary for the benefit of static checking (namely, the various validates_on series of methods now expect an array indexed by field name, rather than a single crazy array with everything mixed-in together).

As for whether "conditions" should be a singular model or array of them, well, I have no idea.

I had to analyze all this in some depth when I was writing the PHPStan extension for Model::find, and it was very difficult to come up with a simple rule to govern all the cases I see in the find documentation.

My first thought was "ah, it's simple! If there's only one argument, then you only get one record back!". But that gets violated by this:

$books = Book::find([1, 3, 8]); // array

so I thought "oh, okay, well if there's only one argument but it's an array, then we go with array". But that gets contradicted by this:

$book = Book::find(['name'=>'Ubik']); // single

And so on. You clearly think that ["conditions"=> ...] should be a single, but based on what rule? I'm not saying you're wrong, I'm just curious to see your gears turning.

I think convention is going to have to drive all this, but I don't really know where to go for the source of truth. This library was launched over a decade ago and was modeled after Ruby's implementation of Active Record, so if you really want to help sort it all out you might see if you can make sense of their documentation:

https://guides.rubyonrails.org/active_record_basics.html

I actually find the docs kind of scattered and hard to read, so even better might be to get Ruby working locally and maybe play around with it.

edit: oh, and I forgot to mention; I wasn't able to find a "conditions"-style interface in the Ruby docs, so maybe it's not a thing, anymore?

Originally posted by @shmax in #42 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions