Editor - "fields" or "field"

Editor - "fields" or "field"

tangerinetangerine Posts: 3,365Questions: 39Answers: 395

Ordinarily I use "fields" for semantic accuracy (plural) in a construct like this:

Editor::inst( $db, 'staff' )
    ->fields(
        Field::inst( 'first_name' ),
         .....

but I've noticed an instance where I used the singular "field" and it still works:

Editor::inst( $db, 'staff' )
    ->field(
        Field::inst( 'first_name' ),
         .....

Is it the case that "fields" and "field" are interchangeable in this context?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    For the most part, Editor->fields() and Editor->field() actually are exactly the same. For convention if it references only a single field the singular should be used, while for multiple fields the plural should be used.

    The one place they diverge is that Editor->field() can be used to get a Field instance back by passing in the string name of the field you want. The plural form is only used as a setter.

    Allan

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Ah, okay. Many thanks, Allan.

This discussion has been closed.