[Top]
Fins
Fins.Model
Fins.Model.DataObject
|
Method Fins.Model.DataObject()->has_many_to_many()
- Method
has_many_to_many
-
void has_many_to_many(.DataModelContext context, string join_table, string that_type, string this_name, string that_name)
- Description
-
define a many to many relationship in which the local object can be linked to many other objects
and vice versa. this requires the use of a join table with two fields: one to contain the id
of each type being linked. Each of the two types will have an attribute that returns the
result of this many-to-many mapping, which we refer to as "this" and "that".
- Parameter join_table
-
the name of the table containing the relationship. typically named in the
form of typeas_typebs.
- Parameter that_type
-
the name of the other type in the relationship (this being the other).
- Parameter this_name
-
the name of the attribute object to be used. often, this is the name of this type.
- Parameter that_name
-
the name of the attribute object to be used. often, this is the name of that type.
- Example
-
// assume we have a field called lists_owners that contains a many-to-many
// mapping of shopping lists to their owners. The data type for this type is "List"
// and the type of the other object is "User". The type of entity for each
// is "owned_list" and "list_owner", respectively. This will result in the List type
// having an attribute called "list_owners" and the "User" type will have one called
// owned_lists.
//
// the table will have 2 fields, called user_id (assuming the primary key of the users
// table is "id" and one called list_id.
has_many_to_many("lists_owners", "User", "owned_list", "list_owner");
- Note
-
it's only necessary to include a call to this method in one of the types in the relation
though doing so in both (with the appropriate values for each) will not cause harm.
- Note
-
if standard naming practices are employed for table names and field names, use of this
method is typically not necessary, as the auto configuration process will detect this.
this function is typically most useful if you want to have multiple many-to-many
relationships that have unique table or attribute names in the resulting objects.
|