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

[eluser]WanWizard[/eluser]
@North2Alaska,

It should not be a problem to overload methods that are defined "protected". What is the problem you have?

[eluser]WanWizard[/eluser]
@rherriman,

Datamapper uses CI's active record library to construct and run queries. It's CI's get() that resets the defined query after execution, which is logical because otherwise the residue would taint the following queries.

There is no way to retain the query, other then perhaps clone the object before the get.

[eluser]North2Alaska[/eluser]
[quote author="WanWizard" date="1332578713"]
It should not be a problem to overload methods that are defined "protected". What is the problem you have?[/quote]

In my Basemodel, I overload the Save function, for example. I need to use the timestamp function to set the updated_field when the created_field is set. So I want to call _get_generated_timestamp(), but it is a private function.

Code:
public function save($object = '', $related_field = '')
{
  $timestamp = parent::_get_generated_timestamp();

When I do this I get an error: PHP Fatal error: Call to private method DataMapper::_get_generated_timestamp()

So, what I ended up doing is just copying the function to Base class and changed the call to
Code:
$timestamp = $this->_get_generated_timestamp()

Obviously, I'm doing something wrong. I'm reading PHP docs to try and understand overloading, but the answer is still eluding me.

[eluser]WanWizard[/eluser]
Ah, they are private, not protected. That's not ok.

Just go into the Datamapper library, and change all "private function" to "protected function". Methods should be extendable.

I'll correct this at the next update.

[eluser]North2Alaska[/eluser]
[quote author="WanWizard" date="1332589199"]Just go into the Datamapper library, and change all "private function" to "protected function". Methods should be extendable.

I'll correct this at the next update.[/quote]

That helps. :-)

When _save_relation is called, I can't figure out how I determine what table is being saved. I've looked at $this->table, but it returns the original table, not the related table. How do I check what fields the join table has? How can I determine if it even is a joining table?

Once again, I kindly ask you to point me in the direction I need to go.

[eluser]WanWizard[/eluser]
It determines the table name using
Code:
$relationship_table = $this->_get_relationship_table($object, $related_field);

If it is the same as $this->table, the foreign key of the relation is in the current table. If not, the table name returned can point to another table, or to a relationship table.

[eluser]rherriman[/eluser]
[quote author="WanWizard" date="1332579007"]@rherriman,

Datamapper uses CI's active record library to construct and run queries. It's CI's get() that resets the defined query after execution, which is logical because otherwise the residue would taint the following queries.

There is no way to retain the query, other then perhaps clone the object before the get.[/quote]

Right, I understand that. I just thought DM must be doing something special, since $product->media will always filter out the Media objects NOT associated with the product without any interference from myself...

[eluser]WanWizard[/eluser]
That is the power of an ORM.

Datamapper knows which records are related, $product->media will only return the subset of related records.

[eluser]rherriman[/eluser]
[quote author="WanWizard" date="1332779778"]That is the power of an ORM.

Datamapper knows which records are related, $product->media will only return the subset of related records. [/quote]

Right. I know. I was just hoping for some insight on how DataMapper was actually making this work, since you can run queries on $product->media multiple times while it retains that "related" query. So DataMapper itself seems to be doing something to circumvent ActiveRecord's "fire-and-forget" query behavior. I actually based my code on what I found within DataMapper's source, but clearly I must have overlooked something somewhere else.

[eluser]WanWizard[/eluser]
Datamapper maintains a data structure internally about all defined relations for this model. So it knows which tables are related, what the foreign keys are, where they are located, if a relationship table is used, etc.

So when you request $product->media, you basically fire a query like "SELECT * FROM media where product_id = x" (where x = $product->id).




Theme © iAndrew 2016 - Forum software by © MyBB