Welcome Guest, Not a member yet? Register   Sign In
DMZ 1.7.1 (DataMapper OverZealous Edition)

[eluser]PoetaWD[/eluser]
Hello,

I was going over the LANGUAGE file to translate the error messages to PT-BR.

I saw some lines that really took my attention:

$lang['related_required'] $lang['related_min_size'] $lang['related_max_size'] $lang['dm_save_rel_failer'] $lang['dm_save_rel_nothis'] $lang['dm_save_rel_noobj']

How can I make a relationship required ?

How can I access that error ?

What is "related_min_size" and 'related_max_size' for ?

Are the answers to thos questions in the docs ?

Btw,

The PT-BR translation that is included in DM is all wrong. Here is a better one:

Code:
<?php

$lang['alpha_dash_dot']        = 'O campo %s deve conter apenas caractéres alfa-numéricos.';
$lang['alpha_slash_dot']    = 'O campo %s deve conter apenas caractŽres alfa-numéricos.';
$lang['min_date']        = 'O campo %s contém uma data inválida.';
$lang['max_date']        = 'O campo %s contém uma data inválida.';
$lang['min_size']        = 'O campo %s deve conter no minímo %s caractéres';
$lang['max_size']        = 'O campo %s não pode exceder %s caractéres';
$lang['transaction']    = 'O %s falhou para %s';
$lang['unique']            = 'Já existe um registro de igual valor para o campo %s que deve ser único.';
$lang['unique_pair']    = 'A combinação %s e %s já está sendo utilizada.';
$lang['valid_date']        = 'O campo %s deve conter uma data válida.';
$lang['valid_date_group']    = 'Os campos %s$s devem conter datas válidas';
$lang['valid_match']        = 'O campo %s deve conter apenas %s';

$lang['related_required']    = 'A relação entre os campos %s é necessária.';
$lang['related_min_size']    = 'A relação %s deve ser no minímo %s.';
$lang['related_max_size']    = 'A relação %s não pode exceder %s.';

$lang['dm_save_rel_failer']    = 'O relacionamento %s não está definido corretamente.';
$lang['dm_save_rel_nothis']    = 'Não foi possível salvar o relacionamento %s: O objeto não está salvo.';
$lang['dm_save_rel_noobj']    = 'Não foi possível salvar o relacionamento %s: O objeto relacionado não foi salvo.';

/* End of file datamapper_lang.php */
/* Location: ./application/language/english/datamapper_lang.php */

[eluser]WanWizard[/eluser]
It is part of the 'required' validation check.

See http://datamapper.wanwizard.eu/pages/val...ated.Rules.

[eluser]paulipv[/eluser]
I have a noob question regarding this tool.
How can i get last inserted id ?

Any docs for helper functions?

[eluser]WanWizard[/eluser]
After you have saved the object, the insert id (if supported by the database driver used) will be assigned to the id property.
Code:
$user = new User();
$user->name = 'John';
$user->save();
echo "John was saved with id ", $user->id;

[eluser]paulipv[/eluser]
Thank you for your quick reply.

While reading docs i stopped at languages => method localize_by_model

Can you explain me what this method do?

Update:

Q1: A language file is loaded only if $model property is defined?

Code:
function __toString()
    {
        return empty($this->name) ? $this->localize_label('newuser') : $this->name;
    }

I guess that method replace the language "name" key if empty but my question is, why is $this->name if in lang config file key is defined like "model_key".

That looks my language config file:

Code:
$lang['users_name']       = 'Name';
$lang['users_email']      = 'Email';
$lang['users_site_url']   = 'Url';

Model name: users

Source:

Code:
class Users extends DataMapper {

    var $table = 'table1';
    var $model = 'users';

    public function getUsers() {

    }

So i guess i call $this->users_name instead of $this->name , correct?



Thank you
paul

[eluser]paulipv[/eluser]
Questions update:

Is posible to execute a join without creating a join table?

[eluser]PoetaWD[/eluser]
Hello, thanks for the previous answer...

Please help me think about this one:

I have the model Client that can be a PERSON or a COMPANY. Not both at the same time...

Is there a validation rule to help me with that ?

If not, is there a better way to do this without a validation rule?

If not, can u help me build a validation rule for it ?

Thanks,,,,

[eluser]PoetaWD[/eluser]
[quote author="paulipv" date="1294850929"]Questions update:

Is posible to execute a join without creating a join table?[/quote]

Yes... if it is a HAS ONE relationship... u just need to add the field YOURRELATEDMODEL_id in the model table...

Example:

Lets say u have the model Owner and the model Dog and u need to relate those. Instead of creating a join table with: id, owner_id, dog_id, you can simple add the field dog_id in the owner table.

I hope u understood my answer and it is the answer u are looking for.

[eluser]WanWizard[/eluser]
@paulipv,

locatisation within Datamapper is used for validation, so that you can translate field names in messages. It is documented here: http://datamapper.wanwizard.eu/pages/localize.html

[eluser]WanWizard[/eluser]
@Poetawd,

There are lots of ways to solve this issue, but it's more application or database design related, and has nothing to do with Datamapper. Datamapper only comes in if you have it implemented in your database, and you need to code the queries for it.

You could add a 'client_type' to the Client table (assuming a person can't suddenly become a company. You can make code that does this, and switches the client_type). You can use a relationship table and set a constraint on it (client_id must be unique for example), you can do a check in your code, you can write a validation method that does a check when you save, etc.

You can even make a multi-relations table, where client has a many-to-many to each of the other tables needing a link to client. And make client_id in that table unqiue.

None of these are Datamapper questions though...




Theme © iAndrew 2016 - Forum software by © MyBB