Where to validate?

Consider following scenario:

I am building a user registration page for my site. I have a FormModel for the registration web form and a ActiveRecord class for the account. After the form is valiated, its attributes are massively assigned to newly created AR instance and second one is saved.

I have 2 questions:

Where is right to validate?

Field like "passowrd", "email" and "username" can be validate in the AR class and also in the FormModel. Where is better?

How to bubble the validation errors?

The uniqueness of username is validated in the AR model. When there is already same username in the database, I need to show error. But I am passing the form model to the view. Is there any kind of "shortcut" to pass the errors from the AR model to the FormModel? Or - is there any undocumented way to check for uniqueness in the FormModel? (the documentation says "no" to this one)…

Thanks in advance!

Using AR is simpler. FormModel is used when you don't have DB as backend.

I defined properties like 'repeatPassword', 'privacyAgreement' and 'rememberMe' (for example) in the FormModel.

According to what you said, I must move these properties to the AR class. Is that correct?

yeah - you can probably dump the form model altogether even

… ok, thanks, last question:

How is better to handle relations then?

If I extend described scenario: Let's say I have Account AR class, and a Profile AR class. They are related like this: "Profile has one account".

At the registration page, for simplicity, I let the user enter his first and family name and username, password and email address. First two - of the Account class, and the last three belongs to the Profile class.

How to build the action without form model then?