Catalogs and enums
Catalogs and their hierarchy, references and objects, enums, constants and deletion marks.
11 questions
JuniorTheoryVery commonWhat is a catalog for, and which standard attributes does it have?
What is a catalog for, and which standard attributes does it have?
A catalog keeps a list of similar items, like goods or customers, that other objects refer to. Its standard attributes are Ссылка, Код, Наименование, ПометкаУдаления and Предопределенный; a hierarchical one also has Родитель.
Common mistakes
- ✗Keeping a list that users extend in an enum: users cannot add enum values, so such a list belongs in a catalog
- ✗Adding
КодandНаименованиеas own attributes: the platform already provides them as standard ones
Follow-up questions
- →When would you switch off a catalog's code or make it a string?
- →Why do documents store a reference to a catalog item rather than its name?
MiddleTheoryVery commonHow does marking an item for deletion differ from deleting it?
How does marking an item for deletion differ from deleting it?
A mark only sets ПометкаУдаления: the item stays in the base, references to it stay valid, and the mark can be cleared. Actual deletion runs later in «Удаление помеченных объектов», which deletes only the marked items nothing refers to.
Common mistakes
- ✗Expecting a marked item to vanish from queries: it stays, and a query must filter on
ПометкаУдаленияitself - ✗Deleting directly instead of marking: references to the item break
Follow-up questions
- →Why do vendor configurations keep the right of direct deletion away from ordinary users?
- →How do you leave marked items out of a query result?
MiddleTheoryVery commonHow does a reference to a catalog item differ from the item's object?
How does a reference to a catalog item differ from the item's object?
A reference points to the item's row in the database: it is stored in attributes and is read-only. An object from ПолучитьОбъект() is an in-memory copy of the item: you change it and save it with Записать(), firing the module's events.
Common mistakes
- ✗Assigning an attribute through a reference: it is read-only, and the change needs
ПолучитьОбъект() - ✗Getting an object only to read one attribute: the whole item is loaded into memory for nothing
Follow-up questions
- →Why does calling
ПолучитьОбъект()for every row of a loop slow the code down? - →What does the run-time error «Поле объекта недоступно для записи» tell you?
JuniorTheoryCommonWhat is a constant in 1C, and when do you use one?
What is a constant in 1C, and when do you use one?
A constant is a metadata object that stores one value for the whole infobase, such as the main company or the start date of accounting. Code reads it with Константы.ОсновнаяОрганизация.Получить() and writes it with Установить().
Common mistakes
- ✗Storing a list of values in a constant: a constant holds one value, a list needs a catalog
- ✗Treating a constant as fixed in code: its value lives in the database, and users change it in Enterprise mode
Follow-up questions
- →When is a periodic information register better than a constant for a setting?
- →How does a constant differ from an enum value?
JuniorTheoryCommonWhere do you store payment methods that users must not change?
Where do you store payment methods that users must not change?
In an enum: the developer sets its values, and a user cannot add new ones
Common mistakes
- ✗Keeping a fixed set in a catalog: users can add and change its items, while only the developer sets the values of an enum
- ✗Expecting a constant to hold a list of values: it holds one value for the whole base
Follow-up questions
- →When is a list of statuses better kept in a catalog than in an enum?
- →How do you compare an attribute with an enum value in code?
JuniorTheoryCommonWhat does the code print (lines separated by spaces)?
What does the code print (lines separated by spaces)?
Да Нет
Open full question →Common mistakes
- ✗Expecting
СоздатьЭлемент()to write the item at once: it creates an object in memory, andЗаписать()writes it - ✗Expecting an unwritten object to have no reference at all: it has an empty one, and
Пустая()returnsИстина
Follow-up questions
- →How can you get a new item's reference before it is written?
- →How does a form handler tell that the object it shows is new?
JuniorTheoryCommonWhat happens when this code runs?
What happens when this code runs?
An error: a reference's attributes are read-only, an object is needed
Open full question →Common mistakes
- ✗Changing an attribute straight through the reference from
НайтиПоКоду: a reference only reads, the object fromПолучитьОбъект()is what changes - ✗Expecting the change to be saved later by itself: nothing reaches the infobase without an object and its
Записать()
Follow-up questions
- →How do you rewrite this code so the new name reaches the infobase?
- →Why should you not call
ПолучитьОбъект()just to read one attribute?
JuniorTheoryCommonHow does a subordinate catalog differ from a hierarchical one?
How does a subordinate catalog differ from a hierarchical one?
A subordinate catalog's items belong to an item of another catalog, the owner, kept in Владелец: contracts belong to a counterparty. A hierarchical catalog nests items of the same catalog into a tree through Родитель, such as goods in groups.
Common mistakes
- ✗Mixing up
ВладелецandРодитель: the owner is an item of another catalog, the parent is a group of the same one - ✗Building a tree of goods as two catalogs, one for groups and one for goods: one hierarchical catalog does it
Follow-up questions
- →How does a hierarchy of groups and items differ from a hierarchy of items?
- →Can one catalog be subordinate and hierarchical at the same time?
MiddleTheoryCommonWhy is reading attributes through a reference inside a loop slow?
Why is reading attributes through a reference inside a loop slow?
Reading Товар.Цена through a reference makes the platform read the whole item from the database, all attributes and table sections included, to return one value. In a loop that means a read per row; get all rows' fields with one query.
Common mistakes
- ✗Reading a referenced item's attributes row by row in a loop: each read loads the whole item, so read them with one query
- ✗Calling
ПолучитьОбъект()just to read values: it loads the whole item as well and costs as much
Follow-up questions
- →How does the library function
ОбщегоНазначения.ЗначенияРеквизитовОбъектаavoid reading the whole item? - →Why does the same problem not arise when the values come from a query result?
MiddleTheoryCommonWhat is a broken reference in a 1C infobase, and where does it come from?
What is a broken reference in a 1C infobase, and where does it come from?
A reference kept in an attribute while its item no longer exists. It comes from deleting an object directly with Удалить(), which skips the reference check, or from loading data without the items. Forms then show «<Объект не найден>».
Common mistakes
- ✗Deleting objects with
Удалить()to tidy the base: it skips the reference check and leaves broken references - ✗Thinking a deletion mark breaks references: a marked item still exists, and references to it stay valid
Follow-up questions
- →How does the processing «Удаление помеченных объектов» decide which items it may delete?
- →How would you find broken references in a database with a query?
MiddleTheoryOccasionalWhat is a chart of characteristic types, and when do you need one?
What is a chart of characteristic types, and when do you need one?
A chart of characteristic types lists property kinds, such as colour or size, each setting the type of its values. With it users add new properties to goods without changing the configuration; values sit in an information register or table section.
Common mistakes
- ✗Adding a new attribute for each new property of goods: a chart of characteristic types lets users add properties themselves
- ✗Expecting the chart to store the values: it lists the kinds, while the values sit in a register or a table section
Follow-up questions
- →Why is the value type of characteristics usually a composite type?
- →How does a query select goods by the value of one characteristic?