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

[eluser]WanWizard[/eluser]
Just name your model 'juser', and in that model set $this->table to 'users' make override the models table name.

[eluser]gowrav vishwakarma[/eluser]
Quote:Just name your model ‘juser’, and in that model set $this->table to ‘users’ make override the models table name.
its not that simple.. you have not noticed the relative field is UID not UID_id ... some how i have managed it to work now second problem .. and this can be helpful to other also

I have a table members, and the members can have another members as friends
its in another table stored as

id | members_id | friends_members_id |approved status

all good from one point "get all friends of member 87"
but the point is in this social application a member can be at members_id as he added a friend or he can be at friends_members_id as his friend added him. now how to get all friends of a member and even only those who are approved !!!

[eluser]WanWizard[/eluser]
If you don't follow Datamapper's design guidelines, you're making it very difficult for yourself, and for us trying to support you.

Self relationships in a many-to-many relation are described in the manual.
Code:
class Member extends DataMapper {
    $has_many = array(
        'friend' => array(
            'class' => 'member',
            'other_field' => 'member'
        ),
        'member' => array(
            'other_field' => 'friend'
        )
    );
}

This will require a relationship table called 'members_members', in which you will have the columns 'id', 'member_id', 'friend_id', and 'approved_status'.

You can then get the list of John's approved friends by using
Code:
$member = new Member();
$member->get_by_name('John');
$member->friend->where_join_field($member->friend, 'approved_status', '1')->get();

[eluser]gowrav vishwakarma[/eluser]
heads off to you...

agreed i have to use guideline .. i am almost near what you said but major question

As per your said I can get all friends of John if he has its id in member_id and friends id in friend_id, what if any of his friend added him in his list then also he is Johns friend. can there be a simple workaround in Datamapper


since I am provided with database by my client this relation ship is in "jos_xshouts_members_has_friends" table with fields
id | member_id | friend_member_id
as per guideline I have gone to this ...
Code:
class Member extends DataMapper{
    var $table='users';
    var $has_many=array(
        'member'=>array(
            'other_field'=>'friend_member',
            'reciprocal' => TRUE,
            'join_table'=>'jos_xshouts_members_has_friends'
        ),
        'friend_member'=>array(
            'class'=>'member',
            'other_field'=>'member',
            'join_table'=>'jos_xshouts_members_has_friends'
        )
    );

but $m=new Member();
$m->friend_member->get() gives nothing, I have also tried $m->member->get() .. but same ..

Thanks for your time

[eluser]WanWizard[/eluser]
Use check_last_query() to see the query produced, and try to deduct from there what is wrong.

[eluser]gowrav vishwakarma[/eluser]
I have read the validation rules but what If i want to save a fields value in encrypted format but it should be displayed in normal way.

like

Code:
$u=new User();
$u->Name='name';
$u->Password='password';  // From validation rule I want it to encrypt
$u->save();

echo $u->Password; // Automatically decrypted from either same encrypt function (some way is needed to knwo weather we are getting or settting) or by another function for get time applicable

[eluser]WanWizard[/eluser]
To encrypt on save, see the prepping example in the documentation, it uses encrypt() as an example.

To decrypt on retrieval, read the section in the manual about "Get Rules" (http://datamapper.wanwizard.eu/pages/getrules.html).

[eluser]Unknown[/eluser]
Hello,

Im trying to use a group_by and a get_paged together, but when i use, the $object->paged->total_rows returns to me the total rows of the first group in the result.

example:
$object->group_by('value');
$object->get_paged($start, $lines_page, true);

if the first row has 12 objects grouped and the result of the query has 2 rows, the $object->paged->total_rows returns to me 12 but the result should be 2. Am i doing something wrong?

[eluser]WanWizard[/eluser]
Have you tested this with the latest version? DMZ 1.7.x is no longer officially supported.

If so, and it is still a problem, please create an ticket at https://bitbucket.org/wanwizard/datamapper/issues, describing the problem and linking back to your message here ( #857 in the titlebar on right gives you the correct link)?

[eluser]Dennis Rasmussen[/eluser]
This is just ridiculous...
Could someone explain to me what kind of method they would use to do such a simple thing (yet so complicated with Datamapper) as being able to create/edit a row in table_1 while creating/updating relations to table_2 with a many:many relation?

Code:
table_1
id - name

table_2
id - title

table_3 (join table)
id(1) - id(2)

So basically I'm having:
- A controller to handle the create/update behavior
- 2 models for the tables, both related to each other as many:many
- A view with a formula with name input for table_1 and a multiselect element having options from table_2

When I submit I'd like the following to happen:
- Create a new row in table_1
- Create rows in table_3 with relations between the new row in table_1 and the multiselected rows in table_2

All of this can easily be done without Datamapper, so why can't I with Datamapper?
Sure I could just do the following, but that seriously can't be healthy for the server with all these objects being created for each relation?

Code:
foreach($this->input->post('multiselect') as $key => $id)
  {
    $t2 = new Table_2($id);
    $t1->save($t2);
  }

Note that the variable names are changed for simplicity.




Theme © iAndrew 2016 - Forum software by © MyBB