Hello,
On 01/17/2003 03:29 PM, Steve Fisk wrote:
> Thanks for your correspondence - I feel a lot happier about the whole thing
> now - it has just taken a whole day of reading the manual, your replies and
> cms.component to get to grips with most things and why you use them where
> you do - two little things still have me a bit befuddled.
>
> Mike has verbally told me that you can have several components that talk to
> the same database provided every class within the component is in the same
> component as one it depends on or has to talk to. How do you set the create
> database option to only create one database and not one for every component?
Metastorage generates classes for creating or updating the database
schemas. You can run the installschema type function as many times as
you want. But on the first time, only the first class you call install
schema may actually create the database, so you have to set the variable
createdatabase to 0 for the other classes.
> Finally - I don't really understand how the addtocollection type function
> works - it might be because it's last thing on a Friday and my brain is
> fried but would you mind running over it with me and then I can get my
> thinking gear around it at some point on Monday?
Don't worry, software modelling is really abstract and so it requires a
lot of concentration.
addtocollection type functions are meant to add objects to a collection
of an object of a given class. For instance, in the cms.component
example, you have articles and categories of articles.
To add a article object to a given category object, there is the
addarticle function of the category class that is of type addtocollection.
So, at run time if you have an category object in variable $c and a
article object in variable $a, you just execute $c->addarticle($a) and,
assuming that it succeded, from them on the article in $a will belong to
the collection named articles of the category object in $c.
Since the articles collection of the categories class references a
member of the article class named categories that is also a collection
pointing back to the categories class, the category object in $c is also
implicitly added to the categories collection of the article object in $a.
This a many to many relationship. An article can be in many categories
and a category may have many articles. Although you should not be
concerned with the actual implementation, this kind of relationship is
implemented with an additional database table that contain references to
the objects of both classes that relate to each other via these
collections.
--
Regards,
Manuel Lemos
>>Is there a set of functions that you would recommend in each class and
>>some that are more specific to Factory? We are starting to understand
>>things a little better now – think we have figured out how the
>>collection tags work - but are still not sure which functions it is
>>important to have in each class and which in the factory class. Have
>>you got any suggestions to that effect or any more detailed examples
>>than cms.component that we could look at?
>
>
> It is actually very simple. Either the factory or the classes will only
> have the functions that you declare in the component definition.
>
> The factory will have functions that create object either from scratch
> or retrieving them from the database, like create a new object of this
> class or get me all objects of this class.
>
> The classes will have functions that to execute actions on objects that
> are already created like save this object to the database or get me all
> objects of some class collection that relate to this object.