Welcome Guest, Not a member yet? Register   Sign In
DataMapper ORM v1.8.2
#81

[eluser]Spir[/eluser]
[quote author="WanWizard" date="1330381378"]Don't think those are related, include_related() should add the related table using a call to _add_related_table(), which is unconditional.

Are you sure the relation is defined properly? If not, no related table will be found and no join will be added...[/quote]My config/relation are OK.
It is correctly working whithout the hack we previously talk about :
http://ellislab.com/forums/viewreply/973083/
I'll digg more this issue…
#82

[eluser]Lunaman[/eluser]
Hey,

Is it possible to set validation rules at runtime?

I have some fields that are not always required, it depends on wich form is submitted.

Greetings
#83

[eluser]Spir[/eluser]
[quote author="Lunaman" date="1330453387"]Hey,

Is it possible to set validation rules at runtime?

I have some fields that are not always required, it depends on wich form is submitted.

Greetings[/quote]You can propably do what you need using a custom function.
Code:
public $validation = array(
'your_field' => Array(
  'rules' => array('trim', '_check_value')
)
);

function _check_value($field)
{
// check if field is required
if (<field is require>)
{
  return (trim($this->{$field}) == '') ? FALSE : TRUE;
}
return TRUE;
}
#84

[eluser]Lunaman[/eluser]
I guess doing the following is acceptable too?

Code:
$object->validation['field']['rules'] = array('trim', 'required', ...);
#85

[eluser]Spir[/eluser]
[quote author="Lunaman" date="1330454898"]I guess doing the following is acceptable too?

Code:
$object->validation['field']['rules'] = array('trim', 'required', ...);
[/quote]yes much better.
#86

[eluser]toadies[/eluser]
I have a question about delete(). I'm trying to figure out why datamapper marks my relationship child id null (or 0) when I delete the parent.

I tried to search and I think this is a common problem.

Parent is Customers table.
Child is Equipments table.

So my relationship should be...

Class Customer
var $has_one = array('equipment');

Class Equipment
var $has_one = array('customer');

When I delete the @ the customer level it updates the equipment table customer_id to 0.

I want datamapper to delete automatically, if not I can delete it manually, but according the the manual it should delete all relationships?
#87

[eluser]WanWizard[/eluser]
It does delete the relationship, it does not delete the related record. These are two different things.

I have to dive into the code to see what the exact rules are for cascading deletes, I'll try to find the time for that later today.
#88

[eluser]toadies[/eluser]
[quote author="WanWizard" date="1330513538"]It does delete the relationship, it does not delete the related record. These are two different things.

I have to dive into the code to see what the exact rules are for cascading deletes, I'll try to find the time for that later today.[/quote]

How do I make equipments the child (relationship) of customers?
#89

[eluser]WanWizard[/eluser]
[quote author="toadies" date="1330517329"]
How do I make equipments the child (relationship) of customers?[/quote]
That depends.

If it is a many-to-many: use a relationship table with FK's to both tables
If it is a one-to-many: either use a relationship table, or store the FK in the 'one' table
If it is a one-to-one: either use a relationship table, or store the FK in one of the the 'one' tables

As for cascading deletes, the logic should be the following, assuming this:
Code:
/*
* Customer has a many-to-one relation with Order. One customer has many orders, an
* order always belongs to a single customer
*/

// get customer with id 10
$customer = new Customer(10);

// and delete it.
$customer->delete();

In this setup, the Order table contains the FK 'customer_id'.

When deleting the customer record, Datamapper will fetch the relation definition from the Customer model, and it will check if 'cascading_delete' is set to TRUE on the relation (which it is by default).

If so, it will check if there is a relationship table. If there is, it will delete the records from that table, but will not delete any Order records.

If there is no relationship table, it will check if Customer or Order contains the FK that defines the relation.

If the FK is in the other table, and the other table is equal to the current objects table (only true in a self-referencing relation) and the FK is in the current table, the FK will be set to NULL, and nothing will happen to the other table.

In all other cases, the related record will be deleted.

After this process, the current record itself will be deleted. If you're using a DB capable of transactions, this entire process is wrapped in a transaction to ensure integrity.

If that doesn't happen, then you have just found a bug.
#90

[eluser]Luis Pacheco[/eluser]
Hi, I can't use CI libraries in my Datamapper model, neither autoloading or local load works, I get the error "Call to a member function encode() on a non-object in ..." (the encrypt library in this case).
Is it possible to use CI libraries in Datamapper models?

Thanks in advance!




Theme © iAndrew 2016 - Forum software by © MyBB