Editor - "fields" or "field"
Editor - "fields" or "field"
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
This discussion has been closed.
Answers
For the most part,
Editor->fields()
andEditor->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 aField
instance back by passing in the string name of the field you want. The plural form is only used as a setter.Allan
Ah, okay. Many thanks, Allan.